Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activating extension 'vscodevim.vim' failed: Invalid regular expression #3522

Closed
tetchel opened this issue Feb 25, 2019 · 14 comments

Comments

@tetchel
Copy link

commented Feb 25, 2019

Describe the bug
When I launch VS Code in Extension Development Host mode, I get an error popup (newlines added by me) saying the following:

Activating extension 'vscodevim.vim' failed: Invalid regular expression: 
/([^\s`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?](?:(?:(?<=[A-Z_])[A-Z](?=[\sA-Z0-9`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]))+|(?:(?<=[0-9_])[0-9](?=[\sA-Z0-9`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]))+|(?:(?<=[_])[_](?=[\s`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]))+|[^\sA-Z0-9`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]*))|[`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?]+|$^/: 
Invalid group.

My condolences to whoever has to work on anything to do with that regex 😨!

To Reproduce

  1. Launch VS Code in Extension Development Host mode.
  2. That's it, the error appears every time.

I can't get the error to pop up when not using Extension Development Host mode. In addition, I tried launching the EDH with two different extensions I work on, and both had the same activation failure message appear, so I don't think it's related to either of my extensions.

Expected behavior
I expect the extension to activate without failing :P

Screenshots
image

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 1.1.0
  • VSCode version: 1.30.2
  • OS: MacOS Mojave

Additional context
I just started noticing this error today. I have been using your extension to develop my own extension for ~6 months so this seems to be a new issue.

Here are my settings, they haven't changed in a long time though so I don't think they are the cause.

"vim.insertModeKeyBindings": [
        {
            "before": ["j", "j"],
            "after": ["<Esc>"]
        },
        {
            "before": [ "<Up>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "<Down>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "<Left>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "<Right>" ],
            "after": [ "<Noop>" ]
        },
    ],
    "vim.normalModeKeyBindings": [
        {
            "before": [ "h" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ ";" ],
            "after": [ "l" ]
        },
        {
            "before": [ "l" ],
            "after": [ "h" ]
        },
        {
            "before": [ "<Up>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "<Down>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "<Left>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "<Right>" ],
            "after": [ "<Noop>" ]
        },
        {
            "before": [ "u" ],
            "after": [ "<Noop>" ]
        }
    ],
@jshap70

This comment has been minimized.

Copy link

commented Feb 25, 2019

I get this in normal mode on windows, not even in extension development mode. Developer tools dumps a stack btw:

[Extension Host] Here is the error stack:  SyntaxError: Invalid regular expression: /([^\s`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?](?:(?:(?<=[A-Z_])[A-Z](?=[\sA-Z0-9`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]))+|(?:(?<=[0-9_])[0-9](?=[\sA-Z0-9`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]))+|(?:(?<=[_])[_](?=[\s`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]))+|[^\sA-Z0-9`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?_]*))|[`~!@#\$%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>/\?]+|$^/: Invalid group
	at new RegExp (<anonymous>)
	at Position.makeCamelCaseWordRegex (C:\Users\jshap\.vscode\extensions\vscodevim.vim-1.1.0\out\src\common\motion\position.js:716:24)
	at new Position (C:\Users\jshap\.vscode\extensions\vscodevim.vim-1.1.0\out\src\common\motion\position.js:85:48)
	at __dirname.load.__awaiter._searchHistory.get.forEach.val (C:\Users\jshap\.vscode\extensions\vscodevim.vim-1.1.0\out\src\state\globalState.js:60:132)
	at Array.forEach (<anonymous>)
	at GlobalState.<anonymous> (C:\Users\jshap\.vscode\extensions\vscodevim.vim-1.1.0\out\src\state\globalState.js:60:18)
	at Generator.next (<anonymous>)
	at fulfilled (C:\Users\jshap\.vscode\extensions\vscodevim.vim-1.1.0\out\src\state\globalState.js:4:58)
	at <anonymous>
	at Generator.next (<anonymous>)
	at fulfilled (C:\Users\jshap\.vscode\extensions\vscodevim.vim-1.1.0\out\src\state\globalState.js:4:58)
	at <anonymous>
@jshap70

This comment has been minimized.

Copy link

commented Feb 25, 2019

afaict the error is with the (?<= statements here to check if the leading character is uppercase: https://github.com/VSCodeVim/Vim/blame/d8564f90a66b414c8698af1514becc5549973263/src/common/motion/position.ts#L855. luckily the regex is commented 🙃

anyways, I don't think positive look-behind exists in all versions of emca

@tetchel

This comment has been minimized.

Copy link
Author

commented Feb 26, 2019

Nice digging jshap, looks like #3483 is the cause, and that's consistent with the new version 1.1.0.

Tagging @JKillian and @jpoon since they worked on that PR.

@jpoon

This comment has been minimized.

Copy link
Member

commented Feb 26, 2019

@JKillian, can you take a look?

@JKillian

This comment has been minimized.

Copy link
Contributor

commented Feb 26, 2019

Thanks for ping everyone. [Positive lookbehinds are part of ES2018] and in the spec. Of course, that doesn't really matter much if it's not implemented anywhere, does it? 😄

Luckily for us, lookbehind regexs shipped unflagged with Node v9. VSCode 1.31 upgrade from Node 8 -> Node 10. @jshap70 could you let me know what version of VSCode you're using? I suspect you're just using an old version.

@tetchel looks like you're using VSCode 1.30.2, which also is a version too old. Can you try upgrading and confirming that the issue goes away?

If people are stuck with old versions of VSCode because of corporate controls or something like that, I see three solutions:

  • Change the regex around to not use lookbehinds (probably possible somehow, just not fun haha)
  • Feature flag the extension so it only runs on VSCode 1.31 and up. Or it could just use a simplified regex on older versions that might not work as well in a few edge cases but still will mostly work.
  • Have people complain to their IT department until they can get an upgrade.

Okay, just joking on that third option 😄but @jshap70 / @tetchel please do let me know if you can upgrade!

@jpoon are you able to see any metrics or anything on what versions of VSCode this extension is used on? Curious to know how many people this would actually impact.

@JKillian

This comment has been minimized.

Copy link
Contributor

commented Feb 26, 2019

Okay, for what it's worth, my recommendation is that we just create a simpler version of the regex (simply by deleting the lookbehind groups) that is used on older versions of VSCode. I think it's worth fixing this because it seems like a fair number of people could be impacted.

Deleting the lookbehind groups doesn't mess things up too much:

With the lookbehinds you get this:
image

Without the lookbehinds:
image

So everything still works pretty well, you just lose the correct behavior in a few edge cases (like where the code says 5AGAIN444).

I don't have time to write a PR for this tonight, but anyone is welcome to if they have the time. Instead of doing regex creation based off VSCode version number (which may work), we could also just try to create the more complicated version of the regex, catch any errors, and create the simpler one if the first try failed.

@jshap70

This comment has been minimized.

Copy link

commented Feb 26, 2019

@JKillian yeah it's not up to date apparently, it's 1.30.2 same as OP. The whole thing was caused by me mixing my arch vscode config into my windows one, and since it's managed by pacman it has "update.channel": "none"... 🤦‍♀

I was actually just playing around with the regex without the lookbehinds, and yeah there's about 3 test cases where the behavior would change without them.

That said, seeing as it was just an out of date issue it seems like you can either just close as not a bug or just version guard like you mentioned.

JKillian added a commit to JKillian/Vim that referenced this issue Feb 26, 2019

JKillian added a commit to JKillian/Vim that referenced this issue Feb 26, 2019

@JKillian

This comment has been minimized.

Copy link
Contributor

commented Feb 26, 2019

I did end up having time to make a quick PR, just to help users on old versions of VSCode: #3525

I didn't get a chance to test it myself on an older version of VSCode though

@tetchel

This comment has been minimized.

Copy link
Author

commented Feb 26, 2019

Confirmed vim works again after upgrading to 1.31.1. Turns out my updates were broken too, this fixed it.

Thanks for figuring that out JKillian

@jpoon

This comment has been minimized.

Copy link
Member

commented Feb 27, 2019

As I'm trying to adhere to https://twitter.com/jasonthepoon/status/1091840637421314048, I'd opt for doing the least amount of work possible which means asking users to update to the latest VSCode.

@tetchel

This comment has been minimized.

Copy link
Author

commented Feb 27, 2019

Yep I think this is an appropriate fix. I'm good to close this if you all are.

@andreimc

This comment has been minimized.

Copy link

commented Mar 6, 2019

@tetchel @JKillian can't install this onto code-server because of this issue. Is there a workaround ?

@JKillian

This comment has been minimized.

Copy link
Contributor

commented Mar 6, 2019

@andreimc perhaps they can update their version of VSCode soon? That said #3525 could fix issues in the interim

@jpoon

This comment has been minimized.

Copy link
Member

commented Mar 11, 2019

As the workaround for users is to upgrade to Code v.1.31 (Feb), closing this issue.

@jpoon jpoon closed this Mar 11, 2019

jpoon added a commit that referenced this issue Apr 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.