microsoft / TypeScript-TmLanguage

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

[TypeScript] Incorrect grammar syntax highlighting #935

Closed talks2much closed 1 year ago

talks2much commented 1 year ago

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

Hi! I was coding with my friend and noticed a few locations in his code, where it was incorrectly highlighted. It seems TS server doesn't affect the highlighting.

Version: 1.73.0-insider Commit: 3544aabd5a2b0da2cd3a6f3fa3f00759aa9d9709 Date: 2022-10-27T21:27:43.984Z Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26

You can reproduce any of these examples on https://vscode.dev. I tried to narrow down all cases and minimize the code required to reproduce, however I can link original full files if needed. Probably some of these cases were already covered by other issues that I failed to find.

Also you most probably would see the difference between GitHub's and VSCode highlighting.

iconType = type as any

Highlighting should be same as for other names like type1, also it fails only when reassigning, eg when used with const works fine.

case-1 Any type typed after as should not be highlighted white


export interface FeatureControl {
    enableCompletionProvider?:
    string
    | {
        processCompletions?(completion: CustomCompletionItem): vsc.CompletionItem[]
    }
}

export interface RegisterLanguageSupportOptions {
    /** handle requesting position in document */
    pathAutoRename?: {
        glob: string
        isSpecCanBeUsed?(specName): boolean | string
    }
}

export interface API {
}

case-2

Works fine, if you reposition or remove first | (usually Prettier likes to position it as demonstrated above!)


type A = B
if (a) const b = a as never

case-3

It also seems to be 100% valid and common case, but the highlighting of statements like if or for without semicolon after type declaration goes with type color.