microsoft / TypeScript-TmLanguage

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

Syntax highlighting: generic type arguments are highly affected by whitespace and other irrelevant context #1014

Open lionel-rowe opened 10 months ago

lionel-rowe commented 10 months ago

πŸ”Ž Search Terms

syntax highlighting generics

πŸ•— Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about syntax highlighting and generics.

⏯ Playground Link

https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXygCMwAeAQQBp4AhKgYQD4AKASgC540BrVHAd1QAoQWDwBnDAWIAmeAF4ppAIxVpVAMwMR4yUTDr5ikgA0qATSoAtLaNQTFAFkN6SggJAr3a9+sE2digCszsSubqbuFu6WfsK29nBiyBAYSiHKqhrMLHEBickYsgou7p5u3m6+2bl2kvkpBsWhpvAW8NasNQkgSSlOTaTuEW5RbjHV2rUEMDCGANruLirwavCarBSLoe4em27le5Xu2XsuLW0dLKfb+8MjhzFuJ4IAul2SOIQAVoYA3u71VIcJaZNYMeAbAE9ArSYE3XY7CpHJ6QtyA9Rw0jnKzPNHQvqYsLhQ6jMbHSEAX2EAHpqfAAHSMwQYACeAAcEMZDNxeAJmeyEGZuagePwhKyOe1haK+UA

πŸ’» Code

declare function abc<A, B, C>(): unknown

const abc2 = abc<1, 2, 3>
const abc3 = abc<X, Y, Z>
const abc4 = abc<
    1,
    2,
    3
>
const abc5 = abc<
    X,
    Y,
    Z
>

const result1 = abc<1, 2, 3>()

const result2 = abc<
    1,
    2,
    3
>()

const result3 = abc<X, Y, Z>()

const result4 = abc<
    X,
    Y,
    Z
>()

const arr = [
    abc<1, 2, 3>(),
    abc<
        1,
        2,
        3
    >(),
    abc<X, Y, Z>(),
    abc<
        X,
        Y,
        Z
    >(),
]

const obj = {
    result1: abc<1, 2, 3> (),
    result2: abc<
        1,
        2,
        3
    >(),
    result3: abc<X, Y, Z>(),
    result4: abc<
        X,
        Y,
        Z
    >(),
}

πŸ™ Actual behavior

Declaring a function signature with generics seems to be pretty robust to changes in whitespace and surrounding context, but passing type arguments is extremely brittle.

This is the preceding code sample in VS Code with the Monokai Pro color scheme:

image

πŸ™‚ Expected behavior

Consistent syntax highlighting:

Additional information about the issue

Original issue in monokai-pro-vscode

Mister-Hope commented 7 months ago

I believe this is the same as my issue https://github.com/microsoft/TypeScript-TmLanguage/issues/876