tree-sitter-nu icon indicating copy to clipboard operation
tree-sitter-nu copied to clipboard

Wrong highlighting in if else statement.

Open CabalCrow opened this issue 1 year ago • 3 comments

Treesitter highlighting fails when else flag is missing a closure else $statement.

Look at the let keywords below. Example without closure: image Example with closure: image

Tested in neovim.

CabalCrow avatar May 22 '24 14:05 CabalCrow

I'm guessing that this has something to do with https://github.com/nushell/tree-sitter-nu/blob/main/queries/nu/highlights.scm. I think it's been a while since the highlights.scm file was updated. I was looking at it last week and noticed that some of the grammar isn't in the file at all. It deserves a good run through if someone has the time.

Well.... maybe the grammar isn't expecting and else without braces. That could probably be changed in the grammar.

fdncred avatar May 22 '24 14:05 fdncred

I think it is straight up a problem with the grammar rather than highlighting. TSPlayground is identifying the let keyword with identifier instead: image

Here how it should look: image

CabalCrow avatar May 22 '24 14:05 CabalCrow

@kit494way any thoughts on this? Do you have time to help update the grammar?

fdncred avatar May 22 '24 15:05 fdncred

In the grammar.js on lines 348 & 366 you have this rule for the else statement:

              field("else_block", $.block),

however the else block can actually take a lot more (compared to if which can indeed only take a block). Adding expressions & commands seems to work for the most part:

                field("else_block", choice($.block, $._expression, $.cmd_identifier)),

Any idea on any other potential elements that could be put after an else?

CabalCrow avatar May 23 '24 17:05 CabalCrow