nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
121 stars 27 forks source link

Wrong highlighting in if else statement. #88

Closed CabalCrow closed 6 months ago

CabalCrow commented 6 months ago

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.

fdncred commented 6 months ago

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.

CabalCrow commented 6 months ago

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

fdncred commented 6 months ago

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

CabalCrow commented 6 months ago

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?