mrcjkb / haskell-tools.nvim

šŸ¦„ Supercharge your Haskell experience in neovim!
GNU General Public License v2.0
432 stars 18 forks source link

lsp inlay hints #364

Closed MangoIV closed 2 months ago

MangoIV commented 2 months ago

Feature description

It would be super cool if you could support the new lsp inlay hints for code lenses, they look much better than what we have now. I also wonder if there's a possibility to make code lenses look a tad nicer, e.g. not include control sequences and excessive amounts of white space (especially in imports).

This will start working with neovim version 0.10!

Thanks for considering!

MangoIV commented 2 months ago

Ah I think this is something to be supported by the hls? What kinda thing are the virtual text then? Why are they not supported by neovim proper? Hmmmm

As always Iā€™m kinda confused

mrcjkb commented 2 months ago

Hey :smile:

inlay hints and code lenses are different LSP requests. It's on the hls roadmap, but I have no idea when it will be done https://github.com/haskell/haskell-language-server/issues/2938.

Activity seems to have picked up recently though.

MangoIV commented 2 months ago

https://github.com/haskell/haskell-language-server/pull/4131

Thereā€™s a GSOC student working on this!

mrcjkb commented 2 months ago

What kinda thing are the virtual text then?

The virtual text you're seeing are code lenses. It's another LSP specification, which I believe has existed for longer than inlay hints. That would explain why hls implemented a lot of things as code lenses, for which inlay hints would be a better fit today.

The main difference is that code lenses come with an action (e.g., you can evaluate doctest snippets, or add imports or type signatures).

MangoIV commented 2 months ago

Do you know whatā€™s up with the control sequences and the spaces on code lenses? Is that something that hls does wrong? Or is this something that happens because all of these guys are written for vscode?

mrcjkb commented 2 months ago

I'm not sure. VSCode does display code lenses differently than neovim, because neovim as a tui doesn't support different font sizes. They are a lot smaller in vscode, so I guess that could be the reason.

MangoIV commented 2 months ago

do you just get these as strings?

mrcjkb commented 2 months ago

haskell-tools doesn't do much, besides enable and auto refresh code lenses by default. The feature itself is implemented in neovim.

MangoIV commented 2 months ago

interesting, why is it that the standard lsp client doesnā€™t display these then? Also do you know where Iā€™d have to go with these issues? I e what may cause the visual noise displayed in some of the code lenses?

mrcjkb commented 2 months ago

why is it that the standard lsp client doesnā€™t display these then?

I think that's just a decision by the maintainer. It could add quite a bit of noise and be too controversial to be enabled by default in neovim core. @mfussenegger, maybe you can answer this better than I can? :smile:

I e what may cause the visual noise displayed in some of the code lenses?

I'm not sure there's a good solution to this, because it would involve overriding vim.lsp.codelens.on_codelens. I do this in my personal config, to add a prefix to the title, but I never really noticed any noise - Do you have a concrete example/screen shot?). That would be too hacky for haskelll-tools though.

MangoIV commented 2 months ago
IMG_3385

this is an example. It has weird amount of spaces, no?

MangoIV commented 2 months ago

Thereā€™s also the case where it renders ā€œline breaksā€ in inferred type signatures.

MangoIV commented 2 months ago

image

MangoIV commented 2 months ago

as you can see it inserts these ^@ and then again, a weird amount of spaces :D

MangoIV commented 2 months ago

image

mrcjkb commented 2 months ago

Ah, I guess those could be so that it inserts formatted text on multiple lines when you call vim.lsp.codelens.run()?

MangoIV commented 2 months ago

I think so, yes, although it has also reliable been messing up these for me šŸ˜‚

MangoIV commented 2 months ago

perhaps one could do something like replacing all consecutive whitespaces by one space in the code lenses? I think that would make it look a lot nicer...

mrcjkb commented 2 months ago

perhaps one could do something like replacing all consecutive whitespaces by one space in the code lenses? I think that would make it look a lot nicer...

Perhaps. But I think this would have to be implemented in neovim core. Overriding the core function is a dirty hack, and would be brittle.

MangoIV commented 2 months ago

argh, that sucks; I don't know if we want to do this in general, do you think i should open an issue in the neovim repo?

mrcjkb commented 2 months ago

There's an open draft PR that reworks codelens rendering:

That might allow overriding the codelens handler properly once it's done. Until then, I would suggest overriding it in your config.

MangoIV commented 2 months ago

Yeah, now I only need to find how, thank you for dropping the link :)

MangoIV commented 2 months ago

https://github.com/neovim/neovim/pull/28807

I went off and fixed it šŸ˜…

MangoIV commented 2 months ago
package = pkgs.neovim-unwrapped.overrideAttrs (old: {
      patches = old.patches or [] ++ [
        (pkgs.fetchpatch {
          name = "strip-consecutive-white-spaces.patch"; 
          url = "https://github.com/mangoiv/neovim/commit/ea0a9163cb37e8444465b81abbed82c54134c12e.patch"; 
          hash = "sha256-LQwS+yJucin5AlXTPa3O95Zwjw4RerniPtNT8ctw0AU=";
        })
      ];
    });