haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.66k stars 355 forks source link

Highlight all occurrences of a duplicated identifier #3596

Open ArturGajowy opened 1 year ago

ArturGajowy commented 1 year ago

HLS (vscode) only highlights the first occurrence of duplicate identifiers, which - at first glance - looks like 'no errors'. Then like 'HLS dead?', and then I realize the squiggly I'm looking for is far up in the file I'm editing. There is information in GHC's error message to highlight both/all occurences.

HLS error message

[{
    "resource": "/home/artur/projects/snip/src/Ex1.hs",
    "owner": "Haskell (snip)",
    "severity": 8,
    "message": "Multiple declarations of ‘z’\nDeclared at: /home/artur/projects/snip/src/Ex1.hs:112:1\n             /home/artur/projects/snip/src/Ex1.hs:137:1",
    "source": "typecheck",
    "startLineNumber": 137,
    "startColumn": 1,
    "endLineNumber": 137,
    "endColumn": 2
}]

Inspecting the messages to check for Multiple declarations of prefix and issuing diagnostics at all relevant lines would be ideal.

michaelpj commented 1 year ago

I think at the moment this is just handled by our generic handling of GHC diagnostics, so we just use the primary location given by the diagnostic.

This would be much easier once we start getting structured diagnostics from GHC, otherwise we'd need to do some special-casing here.

Ideally we'd use the relatedInformation field on Diagnostic for this.