Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Haskell] Fix data constructor definitions #3241

Conversation

deathaxe
Copy link
Collaborator

This PR addresses some points from #3227.

  1. It reorganizes prelude type/constant scopes, so Just, Nothing, Left and Right are highlighted consistently.
  2. It scopes data constructors in data declarations entity.name.constant.
  3. As a preparation for 2.) the strategy to handle [context] => expresssions in class/data/newtype/type declarations had to be changed a bit to (more) reliably. It is mainly required to detect the beginning of data constructor expressions (= Constr), but also helps with some edge cases in the other declarations.

Note: This PR does not scope data types and data constructors differently in normal statements/expressions as no reliable strategy hasn't been found to do so.

According to Haskell's wording ...

- type constructors are scoped `support.type`, `storage.type`
  Type constructors without parameters are called "type".

- data constructors are scoped `support.constant`, `constant.other`
  Data constructors without parameters are called "constant".

  Data constructors denote first class values. As such they can be
  assigned to variables etc.

See: https://wiki.haskell.org/Constructor
Merge class and type contexts as it is not possible to reliably
distinguish both in all situations anyway. The common scope
`storage.type` ensures same highlighting under all circumstances.
This commit...

1. adds some infrastructure to make sure to correctly match 
   `[context] =>` patterns in class/instance/data/type/newtype
   declarations. It's required to reliably match the beginning of
   data constructors.

2. removes `entity.name.class` scoping from instance declarations as
   this was semantically wrong.
This commit limits fully qualified data type matching to 1 after
`deriving` keywords, in case they are not surrounded by parens.

More reliably pop as soon as possible.
This commit adds data constructor expressions in order to 
1. scope constructors `entity.name.constructor` in declarations.
2. add declared constructor names to Symbol List.
3. enable "Goto Definition"

It should improve readability of constructor expressions as the
declared constructor may be tinted differently then the following types
which define its signature.
@deathaxe deathaxe merged commit e29faa3 into sublimehq:master Apr 5, 2022
@deathaxe deathaxe deleted the pr/haskell/fix-data-constructor-definitions branch April 5, 2022 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants