tree-sitter / tree-sitter-haskell

Haskell grammar for tree-sitter.
MIT License
151 stars 36 forks source link

Outermost function when using $ operator isn't parsed as a function #86

Closed seasonedfish closed 2 years ago

seasonedfish commented 2 years ago

When I have multiple functions chained together using the $ operator, the outermost function doesn't get highlighted as a function.

The problem

Here is my code:

exactMatches :: Code -> Code -> Int
exactMatches actualPegs guessPegs =
    length $ filter foundMatch $ zip actualPegs guessPegs where
        foundMatch :: (Peg, Peg) -> Bool
        foundMatch (actual, guess) = actual == guess

Here is what it looks like with the onedark.nvim colorscheme in neovim: image The outermost function, length, is not highlighted the same color as the functions filter and zip. So, I suspect that tree-sitter isn't parsing it as a function.

Expected behavior

I expected length to be highlighted the same color as other functions. When I use parentheses instead, length is highlighted correctly. image

tek commented 2 years ago

looks like this is handled here: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/haskell/highlights.scm#L119

which only triggers for application.

you'll have to create an issue in the nvim-treesitter repo!

tek commented 2 years ago

just noticed that this file is also present in this repo, but in an older state. so I'd say that the other repo is the reference implementation

seasonedfish commented 2 years ago

just noticed that this file is also present in this repo, but in an older state. so I'd say that the other repo is the reference implementation

Wait, so should I still open an issue in https://github.com/nvim-treesitter/nvim-treesitter?

tek commented 2 years ago

yep!

seasonedfish commented 2 years ago

@tek This has been fixed in the nvim-treesitter repo, should I open a PR to merge the changes here?

tek commented 2 years ago

I guess it would make sense to synchronize the queries from nivim-treesitter…go ahead if you like!

seasonedfish commented 2 years ago

Ah wait a second, the file in this repo contains some changes from the one in nvim-treesitter (https://github.com/tree-sitter/tree-sitter-haskell/pull/40), and it looks like both repos have commits since.

Git diff ```diff diff --git 1/highlights.scm 2/Users/fisher/Repositories/nvim-treesitter/queries/haskell/highlights.scm index c7bd156..0e43d18 100644 --- 1/highlights.scm +++ 2/Users/fisher/Repositories/nvim-treesitter/queries/haskell/highlights.scm @@ -73,10 +73,7 @@ "@" ] @operator -(qualified_module (module) @constructor) -(qualified_type (module) @namespace) -(qualified_variable (module) @namespace) -(import (module) @namespace) +(module) @namespace [ (where) @@ -107,26 +104,37 @@ ;; Functions and variables (variable) @variable -"_" @variable.special +(pat_wildcard) @variable (signature name: (variable) @type) (function name: (variable) @function patterns: (patterns)) +((signature (fun)) . (function (variable) @function)) +((signature (context (fun))) . (function (variable) @function)) +((signature (forall (context (fun)))) . (function (variable) @function)) (exp_infix (variable) @operator) ; consider infix functions as operators +(exp_infix (exp_name) @function (#set! "priority" 101)) (exp_apply . (exp_name (variable) @function)) - -("@" @namespace) ; "as" pattern operator, e.g. x@Constructor +(exp_apply . (exp_name (qualified_variable (variable) @function))) ;; ---------------------------------------------------------------------------- ;; Types (type) @type +(type_variable) @type (constructor) @constructor ; True or False ((constructor) @_bool (#match? @_bool "(True|False)")) @boolean + + +;; ---------------------------------------------------------------------------- +;; Quasi-quotes + +(quoter) @function +; Highlighting of quasiquote_body is handled by injections.scm ```

I don't feel confident enough in tree-sitter's query syntax to make the merge, could someone else take a look?

tek commented 2 years ago

according to the commit message of the last big change for this file, it was copied from nvim-treesitter then as well. so I think you should just complete replace it with the current one from there