haskell / haskell-language-server

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

Odd hover behaviour with comments #743

Closed michaelpj closed 10 months ago

michaelpj commented 4 years ago

If I hover over a Haddock comment for a function or any comment preceding such a comment, I get a type hover for the previously declared function without the name.

e.g.

f :: a -> b
-- comment1

-- | comment2
g :: b -> c

Hovering over either comment1 or comment2 I see _ :: a -> b. If there is no preceding function I don't get a hover.

I think this is maybe something wrong with the spans in the HIE files or something? If they were incorrectly being set to "start of function definition -- start of next function definition" then the span for f could cover those comments.

Your environment

Steps to reproduce

I think the example I gave should reproduce, but I extracted it from the middle of my project, so it might not.

Expected behaviour

Probably no hover on comments!

michaelpj commented 4 years ago

A further tidbit: it is essential that g has Haddock, otherwise I also get no hovers appearing. It does not matter if f has Haddock.

pepeiborra commented 4 years ago

I cannot repro with ghcide, but I'm not sure I fully understand the description. A video would help...

A further note. Currently HLS and ghcide handle spans in a completely different way. The HLS way is based in HIE files and it is the future, but it's not yet merged in ghcide, so this issue was moved here prematurely. CC @wz1000

wz1000 commented 4 years ago

Does the file actually compile, or are there some other errors? I can't reproduce, suspect this might be due to position mapping, when we try to reuse stale information.

michaelpj commented 4 years ago

https://asciinema.org/a/CB0w07aTgsRcgeJAYCY8YLbuP

Action starts at 1.10, you can see a variety of weird hovers on comments, with a type corresponding to the binding above. They disappear when I delete the haddock for the binding below.

The file compiles fine. I would say it's something stale, but this persists on a clean start, and it consistently re-appears after I change things!

wz1000 commented 4 years ago

I assume there is no CPP in your file?

michaelpj commented 4 years ago

Nope!

michaelpj commented 4 years ago

The project in question is open-source, so you can try and repro here if you like: https://github.com/input-output-hk/plutus/blob/master/plutus-core/plutus-ir/Language/PlutusIR/Transform/Inline.hs

There's a hie-cabal.yaml in the root which I'm using.

michaelpj commented 4 years ago

I can't reproduce this with the same pattern in other files unless I paste a whole prefix of Inline.hs into them, at which point it starts happening. I haven't pinned down what feature of the file it is that triggers this...

Anton-Latukha commented 2 years ago

Maybe this is fixed by now?

jneira commented 2 years ago

The initial example could be used as a regression test which would be nice to add (if it does not exist)

michaelpj commented 2 years ago

The reason I got stuck on this was that I couldn't reproduce it without a quite chunky example, which was a bit disappointing. I'll try and reproduce with more recent versions.

michaelpj commented 10 months ago

Haven't noticed this recently