tree-sitter / tree-sitter-c-sharp

C# Grammar for tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlight members within a class differently than local variables

rudiejd opened this issue · comments

commented

Minimal example:

class Example {
    private readonly int _member;
    public Example(int member) {
        _member = member;
    }
}

We should have some way to highlight the members within the member assignment differently than we highlight the other local variables (for example, the member argument to Example default constructor.

highlighting in neovim using this parser:
image

highlighting in jetbrains rider:
image

tree-sitter-c-sharp is just a parser - we tokenize the language keywords. These are all just identifiers to us as per the C# Language Specification. We can't know if _member is a variable, parameter, instance variable etc. without a compilation model to resolve variables recursively within scopes.

That is well beyond what tree-sitter and indeed any C# parser is capable off and into compiler territory. To get that you'd need to switch to a language server with a real compiler such as one backed by Roslyn.