microsoft / TypeScript-TmLanguage

TextMate grammar files for TypeScript for VS Code, Sublime Text, and Atom.
MIT License
397 stars 125 forks source link

Regex on new line breaks js/ts highlighter #1024

Open moritztim opened 4 months ago

moritztim commented 4 months ago

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

Putting a regular expression on a new line in JavaScript or TypeScript breaks the highlighter. Steps to Reproduce:

  1. paste this:
    1
    / f(/u/g)
    function f(_: RegExp) {
    return 1;
    }
  2. make sure the language mode is set to TypeScript Expected: Same highlighting as this: u replaced with e

Actual: Highlighting is wrong after the first line.

Theme: @id:vscode.theme-defaults: Dark +

moritztim commented 4 months ago

This happens with a bunch of characters, such as [({})]

mirusky commented 4 months ago

Maybe related to microsoft/vscode#204824

RedCMD commented 4 months ago

how is that not a typescript error? having rogue slashes and/or brackets

moritztim commented 4 months ago

@RedCMD It's 1 divided by f(/u/g), the slashes in the function call being regex notation

moritztim commented 4 months ago

Maybe related to microsoft/vscode#204824

@mirusky From what I understand, the linked issue was a duplicate of microsoft/vscode#203998, which has been traced back to the go formatter used, not vscode,

RedCMD commented 4 months ago

It's 1 divided by f(/u/g)

my bad

looking at the TextMate code looks like a simple fix I'll make a PR soon

change ([dgimsuy]+|(?![\\/\\*])|(?=\\/\\*)) to (?!\\*)[dgimsuy]*((?!\\/)|(?=\\/\\*))

https://github.com/microsoft/TypeScript-TmLanguage/blob/b29f9f8716e5f930d82895246de03e97583cfebc/TypeScript.tmLanguage#L8473