nvimdev / lspsaga.nvim

improve neovim lsp experience
MIT License
3.42k stars 286 forks source link

Add diagnostics to hover info #1349

Open lougreenwood opened 10 months ago

lougreenwood commented 10 months ago

Is your feature request related to a problem? Please describe. A feature I really appreciate about VSCode is that it's hover feature can show both diagnostic info as well as info from the LSP about the code under the cursor.

For example, see this image, here we see diagnostic info ("Expected 1-6 args"...) at the top and then the signature of the function below.

Screenshot 2023-11-18 at 07 18 47

As a user this means that I have less mental burden and one less mapping to juggle, the beauty of the VSCode implementation is that it turns ctrl-k into a generic "show more info about the thing under the cursor", whether it's a line with only diagnostic errors and no other LSP info (i.e just some diagnostic error in a JSON object) or I can see info about the return type of a signature when there are not diagnostics.

Describe the solution you'd like It would be great to see diagnostics implemented into the hover feature. Initially this could be read only (no code-actions), but eventually it would be great to see code actions conditionally shown here too, as a sibling hover dialog adjacent to the main hover or some other UI pattern.

Additionally, because of the flexibility we're used to with nvim, we could even explore further expanding this concept, allowing things like other contextual "sibling" dialogs, possibly things like a contextual menu to "preview definition", "show implementations" etc.

This would make the hover an entry point to further explore the code under the cursor. For my own use cases, I often find myself getting hover info, finding out what a given signature looks like, realise I need to see the definition and then I have to go to that definition. Hover seems like the natural home for co-locating all of this together into a contextually relevant and canonical place.

This kind of pattern helps to simplify the mental models we need to build about how to use a given piece of software. The nature of vim means we need to maintain many mental models, but not all are necessary and this kind of pattern helps to abstract away some of these mental models, remove some mental burden from users and give us cognitive space for more valuable models than trivial ones such as:

Or alternatively:

We don't consciously ask ourselves these questions when we're working, but there is a subconscious process which handles this, and that has a cost. My proposal abstracts this process into an improved, contextual, mulit-purpose hover feature.

Describe alternatives you've considered The closest I've found is https://github.com/soulis-1256/hoverhints.nvim - and when getting the link for this I see that 3 days ago they merged a large update which implements diagnostics and the next step is to build diagnostics & lsp info into the same hover.

So maybe there is one alternative coming?

glepnir commented 10 months ago

can add an option to enable this.