fisheva / Eva-Theme

A comfortable and semantic theme.
https://marketplace.visualstudio.com/items?itemName=fisheva.eva-theme
MIT License
452 stars 38 forks source link

Fix `infer`, `is` , type param and string literal as key of object for typescript #114

Closed sharpchen closed 9 months ago

sharpchen commented 9 months ago

Scopes

keyword scope
infer keyword.operator.expression.infer.ts
is keyword.operator.expression.is.ts
entity.name.type.ts
string.quoted.single.ts,punctuation.definition.string.end.ts,punctuation.definition.string.begin.ts

Code sample

function isString(o: string | number): o is string {
    return typeof o === 'string';
}
const a: string | any = {};
if (isString(a)) {
    console.log(a.length);
}
const arr = [1, 2, 3, 'a'];
const b = arr.filter((e): e is string => typeof e === 'string');
type M<T> = unknown;
type First<T extends any[]> = T extends [infer TFirst, ...infer _] ? TFirst : never;
type Length<T extends any[]> = T extends { length: infer TLength } ? TLength : never;
type MyExclude<T, U> = T extends U ? never : T;
type D = MyExclude<1 | 2 | 3, 3>;
type Bar = {
    'foo': 1;
    'bar': {
        'foo': 'bar';
        'baz': 'foo';
    } | any;
};
const map = {
    'foo': 1,
    'baz': {
        1: 'foo',
        'bar': 1
    },
    'bar': 'bar'
};
function f(p: Bar) { }
f({ 'foo': 1, 'bar': {} });

Screenshots

Before After
before after
before after
sharpchen commented 9 months ago

infer is very similar to var pattern in csharp, both work for inline declaration, however applied on type. That's why I make it #A78CFA.

Span<int> span = stackalloc int[1024];
if (span is [var first, .. var _])
{
    Console.WriteLine(first);   
}
if (span.ToArray() is { Length: var length })
{
    Console.WriteLine(length);
}
type First<T extends any[]> = T extends [infer TFirst, ...infer _] ? TFirst : never;
type Length<T extends any[]> = T extends { length: infer TLength } ? TLength : never;
fisheva commented 9 months ago

The colors provided for the is and infer are correct.

WX20240101-161626 The object properties inside the green box have the wanted color, while the properties inside the red box are the result of the inability of VSCode to differentiate the scope values.

@sharpchen Happy New Year! Best wishes to you! : D

sharpchen commented 9 months ago

@fisheva 🤗Happy New Year By the way, what about the type param, it seems you didn't merge it.

fisheva commented 9 months ago

Adding entity.name.type.ts will overwrite the rule meta.type.parameters entity.name.type, but the T and U in angle brackets are intentionally set to the color of parameters #F0AA0B because they are generic parameters.

WX20240102-225911@2x The desired implementation is for the T and U inside the red box to also be displayed with #F0AA0B , similar to function parameters. It may achieve this in the future relying on semantic token color customizations.