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

Typescript syntax highlighting breaking on certain regex following ! #806

Closed
zajrik opened this issue Feb 14, 2020 · 9 comments
Closed

Typescript syntax highlighting breaking on certain regex following ! #806

zajrik opened this issue Feb 14, 2020 · 9 comments

Comments

@zajrik
Copy link

zajrik commented Feb 14, 2020

  • VSCode Version: 1.43.0-insider (user setup)
  • OS Version: Windows 10 pro

Steps to Reproduce:

  1. Fresh install of VSCode Insiders (Also occurring on stable)
  2. Paste the following code into a file:
class Foo {
    public foo(): boolean {
        return !/[():\w]/.test('foo');
    }

    private bar(): void {}
}

Does this issue occur when all extensions are disabled?: Yes

Funnily enough, it appears this code breaks GitHub's syntax highlighting as well.

Escaping the parens will fix syntax highlighting on the remainder of the document, but the syntax highlighting on the regular expression itself is still broken. Removing the ! and not escaping the parens fixes everything, but obviously that completely changes the meaning of the code.

Here's the example above:
image

And here's the prominent example in my code that sparked this issue:
image

The last screenshot is from stable with all my extensions, however I can confirm it appears similarly broken on a fresh insiders install with no extensions.

@mjbvz mjbvz transferred this issue from microsoft/vscode Feb 14, 2020
@mjbvz mjbvz removed their assignment Feb 14, 2020
@mjbvz
Copy link
Contributor

mjbvz commented Feb 14, 2020

Confirmed with the latest grammar from master

@zajrik
Copy link
Author

zajrik commented Feb 25, 2020

I gotta tell ya, this does not feel right at all:
image

But at least I can work again 🤷‍♀️

@zajrik
Copy link
Author

zajrik commented Feb 25, 2020

Another potential solution would be to simply take the inverse of the character set in the regular expression itself, like:

if (/[^():\w]/.test(reader.peek(index)))
    return false;

I ended up using this a few times today in some new code, but this solution is of course not always viable.

Hope to see some resolution to this issue soon.

@infinnie
Copy link

infinnie commented Mar 2, 2020

Funnily enough, it appears this code breaks GitHub's syntax highlighting as well.

Due to GitHub using this as their TypeScript syntax highlight grammar.

@zajrik
Copy link
Author

zajrik commented Mar 2, 2020

That makes a lot of sense.

@qsniyg
Copy link

qsniyg commented Mar 2, 2020

The way I worked around this issue was to just add parenthesis around the expression:

!(/regex/.test(...))

@zajrik
Copy link
Author

zajrik commented Mar 3, 2020

Oh, I hadn't considered that under the assumption that it would throw warnings due to the no-extra-parens typescript-eslint rule but I tested it just now it looks like it doesn't. Good to know. Obviously a fix for this problem is still the desirable solution, though.

@mjbvz
Copy link
Contributor

mjbvz commented Mar 16, 2020

@sheetalkamat When you have a chance, can you or someone on the TS team please take a look at this. We're seeing a lot of reports on the VS Code side but I had trouble figuring out what's going wrong in the grammar

@KostyaTretyak
Copy link

In VS Code v1.43.2, the issue and microsoft/vscode#92904 does not seem to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants