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

Semantic Tokens treats a standalone deriving strategy as type parameter #3983

Closed
Tracked by #3931
konn opened this issue Jan 19, 2024 · 4 comments · Fixed by #3958
Closed
Tracked by #3931

Semantic Tokens treats a standalone deriving strategy as type parameter #3983

konn opened this issue Jan 19, 2024 · 4 comments · Fixed by #3958
Assignees
Labels
component: semantic-tokens type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@konn
Copy link
Collaborator

konn commented Jan 19, 2024

Your environment

Which OS do you use? macOS Sonoma14.2.1(23C71)

Which version of GHC do you use and how did you install it? GHC 9.2.8 via GHCup

How is your project built (alternative: link to the project)? By cabal-install. This can happen in any project, but see linear-extra.

Which LSP client (editor/plugin) do you use? VSCode

Which version of HLS do you use and how did you install it? 2.6.0.0, via ghcup-vanilla-0.0.8.

Have you configured HLS in any way (especially: a hie.yaml file)? No. Auto Detection.

Steps to reproduce

Adds a standalone deriving clause with explicit deriving strategy with Semantic Tokens enabled.

{
  "haskell.plugin.semanticTokens.globalOn": true,
  "editor.semanticHighlighting.enabled": true
}

Example. Consider the following:

type LocAddr :: Location -> Type
newtype LocAddr s = LocAddr {getLocAddr_ :: LocAddr_}
  deriving (P.Eq, P.Ord)
  deriving newtype (Hashable)

In above, newtype is treated as keyword correctly:

newtype-deriving

Next, make Hashable instance deriving standalone:

deriving newtype instance Hashable (LocAddr s)

Then newtype is rendered differently!

deriving-newtype-standalone

Changing newtype to anyclass gives the same effect. If we change it to via LocAddr_, via is rendered correctly.

Expected behaviour

Both newtype and anyclass must be treated as keyword.

Actual behaviour

Treated as parameter, as above. Here is the token inspection result from VSCode:

スクリーンショット 2024-01-19 14 11 04

Debug information

Here is the trace log of VSCode:

vscode.log

@konn konn added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. status: needs triage labels Jan 19, 2024
@soulomoon
Copy link
Collaborator

soulomoon commented Jan 19, 2024

Thank you for your bug report. Interesting case, I’ll take a look later

@soulomoon

This comment was marked as resolved.

@soulomoon
Copy link
Collaborator

soulomoon commented Jan 19, 2024

I can reproduce now. It seems the type variable s is included in the newtype location in hieAst when deriving.

    Node@hello.hs:59:10-16: Source: From source
                            {(annotations: {(NewtypeStrategy, DerivStrategy)}),  (types: []), 
                             (identifier info: {(name s,  Details:  Nothing {type variable binding with scope: LocalScope hello.hs:59:27-42 , type variable scopes:})})}

possible fix would be walk to along with the lexed source: #3958 (comment), to prevent the generated token from appearing

@soulomoon
Copy link
Collaborator

soulomoon commented Jan 22, 2024

shoud be fixed by #3958.

Screenshot 2024-01-22 at 21 56 54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: semantic-tokens type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
3 participants