tree-sitter / tree-sitter-c-sharp

C# Grammar for tree-sitter
MIT License
177 stars 47 forks source link

Generic methods not highlighted correctly #298

Closed musjj closed 1 year ago

musjj commented 1 year ago

Casting using a generic method is highlighted incorrectly, when it's assigned to a variable.

image

damieng commented 1 year ago

Tree-Sitter Grammars do not, themselves, do any syntax highlighting.

What IDE/editor/viewer are you using?

musjj commented 1 year ago

Sorry for not being specific, I guess. I'm using neovim, and it seems that problem isn't the highlighting, but the fact that they're not parsed correctly:

With variable assignment ![image](https://user-images.githubusercontent.com/72612857/221386083-ffbaeb26-56de-404b-9726-dd24d9d3e7f3.png) ![image](https://user-images.githubusercontent.com/72612857/221386111-17d1f5be-d905-456b-8be2-5c3893e76903.png)
Without variable assignment ![image](https://user-images.githubusercontent.com/72612857/221386123-34c39a8d-4347-4ea3-813c-8bcf11020d41.png) ![image](https://user-images.githubusercontent.com/72612857/221386147-0f2f0828-5ffc-43fa-8812-da5775fa7dc1.png)
damieng commented 1 year ago

Your block of code parses as:

  (compilation_unit
      (global_statement
        (local_declaration_statement
          (variable_declaration
            (identifier)
            (variable_declarator
              (identifier)
              (equals_value_clause
                (invocation_expression
                  (generic_name
                    (identifier)
                    (type_argument_list
                      (identifier)))
                  (argument_list
                    (argument
                      (string_literal)))))))))
      (global_statement
        (expression_statement
          (invocation_expression
            (generic_name
              (identifier)
              (type_argument_list
                (identifier)))
            (argument_list
              (argument
                (string_literal)))))))

So both of them are mapping to the exact same block during the parsing phase. I checkout our tagging system which is used by highlighters as well:

image

While I'm not familiar with NeoVIM I would suggest trying to disable OmniSharp to see if the syntax on first then matches the syntax on the second.

musjj commented 1 year ago

I've turned off the LSP, but no luck. image Weirdly, it seems that it got parsed as a binary expression for me. I wonder if my parser is outdated or something...

damieng commented 1 year ago

I've found this - it seems to be a very recent regression, let me investigate.

damieng commented 1 year ago

Regression introduced in https://github.com/tree-sitter/tree-sitter-c-sharp/pull/294 which also shows a lack of these use cases in the corpus tests.

damieng commented 1 year ago

Should now be working correctly here - neovim-tree-sitter will need to update their reference to the latest commit on master.

musjj commented 1 year ago

Thanks a lot for the swift response! I'll give it a go once they bumped up the commit in the repo.

musjj commented 1 year ago

This is fixed now, thanks a lot!