tree-sitter / tree-sitter-haskell

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

Fix associated types failing if unannotated #88

Closed lf- closed 2 years ago

lf- commented 2 years ago

I noticed that the following snippet was getting broken syntax highlighting:

class
  (FromJSON (ResultType query), ToJSON (GraphQLParams query)) =>
  GraphQLQuery query
  where
  type ResultType query
  type GraphQLParams query

  graphqlQuery :: Text

I looked into it, and found this AST:

The AST ``` context [61, 2] - [61, 64] constraint [61, 3] - [61, 30] class: class_name [61, 3] - [61, 11] type [61, 3] - [61, 11] type_parens [61, 12] - [61, 30] type_apply [61, 13] - [61, 29] type_name [61, 13] - [61, 23] type [61, 13] - [61, 23] type_name [61, 24] - [61, 29] type_variable [61, 24] - [61, 29] comma [61, 30] - [61, 31] constraint [61, 32] - [61, 60] class: class_name [61, 32] - [61, 38] type [61, 32] - [61, 38] type_parens [61, 39] - [61, 60] type_apply [61, 40] - [61, 59] type_name [61, 40] - [61, 53] type [61, 40] - [61, 53] type_name [61, 54] - [61, 59] type_variable [61, 54] - [61, 59] type_apply [62, 2] - [67, 14] type_name [62, 2] - [62, 14] type [62, 2] - [62, 14] type_name [62, 15] - [62, 20] type_variable [62, 15] - [62, 20] type_name [63, 2] - [63, 7] type_variable [63, 2] - [63, 7] type_name [64, 2] - [64, 6] type_variable [64, 2] - [64, 6] type_name [64, 7] - [64, 17] type [64, 7] - [64, 17] type_name [64, 18] - [64, 23] type_variable [64, 18] - [64, 23] type_name [65, 2] - [65, 6] type_variable [65, 2] - [65, 6] type_name [65, 7] - [65, 20] type [65, 7] - [65, 20] type_name [65, 21] - [65, 26] type_variable [65, 21] - [65, 26] type_name [67, 2] - [67, 14] type_variable [67, 2] - [67, 14] ERROR [67, 15] - [67, 17] ```

From this I observed that the associated types were eating the entire class declaration. This seemed not quite right. I reduced the example and found that the parser didn't know about associated types declared without :: Type kind annotations.

Please let me know if I did anything not quite right; this is my first time working on a treesitter parser.

tek commented 2 years ago

thanks, that is indeed an oversight!