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

Two dots in guard clause cause syntax highlighting issue in Helix

Open michaeljones opened this issue 1 year ago • 4 comments

When I have code like:

    http.Get, [".well-known", "webfinger"] ->
      case host {
        value if value == config.connection.host -> web_finger_page(req, config)
        _ -> wisp.not_found()
      }

in a case statement, the syntax highlighting fails on the second . in config.connection.host.

Louis was able to reproduce it and I did my best to check with the latest commit from this repo via an entry in the Helix languages.toml.

Grateful for Gleam, this project and Helix :)

michaeljones avatar Jan 20 '24 11:01 michaeljones

Good find! It looks like this is a Helix bug rather than anything wrong in tree-sitter-gleam. The problem is this highlight pattern: https://github.com/gleam-lang/tree-sitter-gleam/blob/62c5388a7badb4e29315690358267a76a734bf83/queries/highlights.scm#L17-L20

Also see #7: tree-sitter previously did not allow us to gate more than one capture (@module and @function) behind the #is-not? local predicate. As a result, connection is always tagged as a @function even if config is a local. We fixed the behavior of that pattern a while ago upstream in tree-sitter but I never ported the necessary change to the highlighting code to Helix (https://github.com/tree-sitter/tree-sitter/pull/1602/files#diff-538bdc046297d41717e7a863a54456d47829fb2e298963198cdfb32684500cdd). I'll make a PR for that change in Helix.

the-mikedavis avatar Jan 20 '24 14:01 the-mikedavis

I have the same behaviour in Neovim. Do they have the same bug?

lpil avatar Jan 21 '24 10:01 lpil

I would bet that nvim also needs to add the equivalent of QueryMatch::remove in their locals calculation. (For nvim I believe it would be ts_query_cursor_remove_match since they use the C bindings.) I can take a look at fixing that in nvim as well

the-mikedavis avatar Jan 22 '24 14:01 the-mikedavis

Ah actually it looks like nvim is using different highlights https://github.com/nvim-treesitter/nvim-treesitter/blob/cd4e0909948eb33d3959e133c16f837e4db122c6/queries/gleam/highlights.scm

And nvim doesn't support #is-not? local yet: https://github.com/nvim-treesitter/nvim-treesitter/blob/97997c928bb038457f49343ffa5304d931545584/queries/ruby/highlights.scm#L165-L167

So nvim might need a different fix for its highlights

the-mikedavis avatar Jan 22 '24 16:01 the-mikedavis