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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: Add semantic token type (or allow add-only setting) #1

Open
Meligy opened this issue Sep 21, 2023 · 1 comment
Open

Comments

@Meligy
Copy link

Meligy commented Sep 21, 2023

Hello,

First, thanks heaps for the great extension. I love it. It adds more fun to development.

That even the one instance that it doesn't apply to is bothering me 馃槀

In the language C#, there's a concept called extension methods. These are functions you import and then you call them on object as if they were defined on the class or struct of this object's type.

Example:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

static class PersonExtensions
{
    // Add method GetFullName to Person class
    static string GetFullName(this Person value)
        => $"{value.FirstName} {value.LastName}";
}

var person = new Person() { FirstName = "Joan", LastName = "Smith" };
var FullName = person.GetFullName(); // call extension method as if it's part of Person class
Console.WriteLine(FullName);

The extension method is not supported by Colormate, and I happened to have a theme ("Noctis Minimus") that makes it look quite unobvious:

image

So, I wanted to add it. I inspected the entity:

Got this:

image

Now, to add Colormate support for this, the way I found was to add "extensionMethod" to the setting colormate.semanticTokenTypes.

I also tried adding "other" or "Other" based on the investigation but it didn't work

So, it'd become like this:

    "colormate.semanticTokenTypes": [
        // "Other",
        "extensionMethod",

        // I have to copy default `colormate.semanticTokenTypes`
        // This means I lose sync if they get updated in the future in Colormate itself
        "entity",
        "class.defaultLibrary",
        "class",
        "enum",
        "enumMember",
        "event",
        "function.defaultLibrary",
        "function",
        "interface",
        "macro",
        "method",
        "namespace",
        "parameter",
        "property.readonly",
        "property",
        "struct",
        "type.defaultLibrary",
        "type",
        "variable.readonly.defaultLibrary",
        "variable.readonly",
        "variable"
    ]

This fixes it:
image

In case you are wondering about colors, I also have these settings:

 "colormate.darkTheme.lighting": 80, 
 "colormate.darkTheme.saturation": 75, 
 "colormate.hasDefaultTextMateTokenScopes": false

However, VS Code does not allow me to only add to the existing array. It only allows me to override it. It gets me started with the current default values, but if they change in the future, I won't notice.

So, I'm suggesting one of the following:

  1. Adding another setting like colormate.additionalSemanticTokenTypes that adds to the existing list, kinda similar (opposite) to excludedTextMateTokenScopes
  2. Or just adding "extensionMethod" on your end
    • Or maybe more generic token type even
      I tried a few like "other"/ "other"and even "entity.name.function.extension.cs" but no luck

Finally, sorry for the long issue. I wanted to be as thorough as possible.

Cheers,

@Sawtaytoes
Copy link
Owner

Sawtaytoes commented Nov 13, 2023

Whoa! Somehow I missed this ticket.

I think your request is completely valid. I actually did that for TextMate scopes, but it's lacking for VSCode's semantic scopes because I was going to add them all anytime they changed (and they haven't changed).

I tried this with C# (not changing any settings), and it colored GetFullName correctly:

image

None of the other stuff colored though.

The reason entity.name.function.extension.cs didn't work for you is because it's a TextMate scope:

image

TextMate scopes are what set ColorMate apart from other solutions.

Those TextMate scopes let you have granular control over highlighting including ones that aren't available in VSCode like these import variables:

image

I'm curious how you got "extensionMethod" working since it's not documented here: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#predefined-textmate-scope-mappings

There are other tokens on that page too which I didn't specify, but they're not the exact tokens; it's more of a general overview: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers.

Is there another place they've documented these selectors on a per-language basis?

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

2 participants