kosayoda / nvim-lightbulb

VSCode 💡 for neovim's built-in LSP.
MIT License
801 stars 30 forks source link

Show lightbulb when code action is available on the current line #10

Closed morgsmccauley closed 1 year ago

morgsmccauley commented 3 years ago

Is it possible to show a 💡when a code action is available on the current line? And then list all available code actions for the line? It can be easy to miss a potential code action if my cursor needs to be in specific position.

kosayoda commented 3 years ago

Hi, I doubt that is possible, since code actions are position dependant on the LSP server side, and the server will not return a code action for let's say, swapping function parameters if I ask for a code action for the entire line.

A workaround would be to ask the server for possible code actions for every single column on the line, but I feel that it would be very resource intensive and not worthwhile.

ayoubelmhamdi commented 3 years ago

I also want this future

RaafatTurki commented 2 years ago

@kosayoda how do other IDEs handle this, as they seem to be able to "query" the language server for a list of available code actions

kosayoda commented 2 years ago

@RaafatTurki Do you have an example of this? As far as I am aware this isn't a feature of any LSP based IDEs.

danielo515 commented 2 years ago

can't you use tree sitter to only query for relevant information? Like find all arguments, functions and so and ask for their columns? But now that I think about it, that's not how tree sitter works? it doesn't allow you to ask what is in this line? or does it?

kosayoda commented 2 years ago

can't you use tree sitter to only query for relevant information? Like find all arguments, functions and so and ask for their columns? But now that I think about it, that's not how tree sitter works? it doesn't allow you to ask what is in this line? or does it?

Interesting suggestion. On first thought that might work (making a codeAction call on every node in the triggered line). Some thoughts:

  1. If a lightbulb shows up whenever there is a an action on the current line, the user would still have to hunt for the relevant node/position in order to actually get the list of code actions, partially defeating the purpose. That being said, writing this out gave me the idea of having different indicators for when an action is available anywhere on a line vs at the current cursor position.

  2. A line may still have enough nodes to degrade performance. Apart from LSP overhead, we also need to run/parse treesitter queries to get a list of nodes on the current line. Admittedly this is not an issue until such a feature exists and benchmarks are ran (I don't have enough knowledge to perform such a benchmark).

  3. It introduces a dependency on treesitter. This may not be a problem if we can make it optional.

TLDR: The suggestion sounds interesting and I will be playing around with the idea when I have time. I'm still not sure the feature is worth the implementation, so I'd be happy to review a proof-of-concept version of this feature if anyone is interested.

RaafatTurki commented 2 years ago

@kosayoda A max limit per line can be set, and have that configurable per language server.

Also caching the code action results so the user wouldn't have to ask for them again is a good idea, this opens so many doors regarding displaying them for instance we could have them all show in one vim.ui.select call with separators between them.