Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add unicode support for \w regexps - #667

Merged
benogle merged 7 commits into
atom:masterfrom
nixel2007:fix-76-unicode-support
Feb 23, 2016
Merged

benogle merged 7 commits into
atom:masterfrom
nixel2007:fix-76-unicode-support

Conversation

@nixel2007

Copy link
Copy Markdown
Contributor

Hello.
This is a fix for long-lived bug #76 - autocomplete is broken for non-ascii symbols (cause of \w-implementation as [a-zA-Z0-9_])
I took @l-flame idea of adding XRegExp and replacing \w to [\p{L}\d_] + some tuning for \b (it's also based on \w).

All 218 specs are "green".

@EvilBeaver

Copy link
Copy Markdown

There are more similar issues in Atom. For example #100 #573 and so on.
It seems this pull request fixes all cases of this bad unicode support.

@artbear

artbear commented Feb 8, 2016

Copy link
Copy Markdown

+1

@lee-dohm lee-dohm changed the title Fix #76. Add unicode support for \w regexps Add unicode support for \w regexps Feb 8, 2016
@benogle

benogle commented Feb 8, 2016

Copy link
Copy Markdown
Contributor

This is interesting. One thing that's a little nervewracking is that it's pulling in a new regex library that has a lot of unknowns. We dont know if it's slow, we dont know what other issues are in there, and we dont know about the edges no one has thought about.

I think the right way forward should be:

  1. Make an option, default false, that when enabled, uses this library. When the option is false, it uses built-in regexes as it does today.
  2. Do some profiling of this library vs native regexp
  3. Write specs for a number of unicode cases that utilize all the changed regexes

@nixel2007

Copy link
Copy Markdown
Contributor Author

Hi, @benogle

  1. I think that making an option is not a good idea. I see request about this feature since 2014 year. People really waits for this for a long time.
  2. If you have some fears about lib, we can extract the /p{L} sequence and use it like this:
Letters = "0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\_and_so_on_and_so_on"
...
wordPrefixRegex: RegExp ('^[' + Letters + '\\d_]+[' + Letters + '-\\d_]*$')

So, you have no extra dependencies AND have needed behavior.
Nevertheless, XRegExp is widely used lib. Search result on github. I think simple /p{L}-request can't break anything
3. Specs is always a good idea.

@winstliu

winstliu commented Feb 8, 2016

Copy link
Copy Markdown
Contributor
  1. I think that making an option is not a good idea. I see request about this feature since 2014 year. People really waits for this for a long time.

Having an option makes sure that there are no regressions, and people can enable/disable it at will. This was the same approach done for fuzzy finding (which had even more requests, also since 2014) and other major features such as preview tabs or the Shadow DOM. After a while if everything is proven stable then the default can be switched to true or even removed (as in the case of preview tabs).

@nixel2007

Copy link
Copy Markdown
Contributor Author

@50Wliu do you think this option should be editor-wide or could be specified for specific language?

Me and my colleauges tested it for our language package (in both ascii and non-ascii variants). it would be great if we could turn this flag on when package activate()

@nixel2007
nixel2007 force-pushed the fix-76-unicode-support branch from b76368e to 6048840 Compare February 18, 2016 08:08
@nixel2007
nixel2007 force-pushed the fix-76-unicode-support branch from 75b6001 to 3aecf17 Compare February 19, 2016 08:29
New setting turns on the extended regexes instead of classic \w
@nixel2007
nixel2007 force-pushed the fix-76-unicode-support branch from 082bf70 to 16d45c4 Compare February 19, 2016 13:09
@nixel2007

Copy link
Copy Markdown
Contributor Author

Here some updates for this PR.

  1. Removed xRegExp dependensy (see section with profiling).
  2. Rewrited old providers specs with unicode support
  3. Added a new package setting enableExtendedUnicodeSupport - "Identifies non-latin alphabet characters as letters". Turned off by default.
  4. Made some profiling for getSuggestions in REALLY LARGE dictionary file.

enableExtendedUnicodeSupport is disabled:
falseenableextendedunicodesupport

enableExtendedUnicodeSupport is enabled:
trueenableextendedunicodesupport

old version with XRegExp-lib:
xregexp

As you can see, time for all three variants is nearly equal, within the measuring error.
Please, review. @benogle @50Wliu

Maybe you'll want to get xRegExp dep back or hide letters variable in some module, to reduce the width of file and code duplication

benogle added a commit that referenced this pull request Feb 23, 2016
@benogle
benogle merged commit 660eb27 into atom:master Feb 23, 2016
@benogle

benogle commented Feb 23, 2016

Copy link
Copy Markdown
Contributor

Thanks for this!

@benogle benogle mentioned this pull request Feb 23, 2016
@TimvdLippe

Copy link
Copy Markdown
Contributor

Amazing news, thanks for the hard work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants