autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 272 forks source link

Properly customizable context menu #1196

Open maujim opened 3 years ago

maujim commented 3 years ago

Is your feature request related to a problem? Please describe.

After reading the docs, I couldn't seem to find a way to edit the entries in the context menu. After poking around in the source code however, I saw that it is doable. I did it by overriding the LanguageClient_contextMenuItems() function in my .vimrc. I'm wondering if there is a better way to enable this feature.

Describe the solution you'd like

I'd like to be able to edit the entries of the context menu by just declaring a variable in my .vimrc instead of having to override a function. I'm thinking a possible implementation would be to have a g:LanguageClient_contextMenuItems that can be set by the user.

Based on what I've seen, it would be easy to just replace the contextMenuItems function with a variable since all the function does is return a dictionary.

Describe alternatives you've considered

Alternative I've considered (and implemented) is overriding the contextMenuItems.

martskins commented 3 years ago

I honestly think context menu should actually be displaying items that make sense in the current context, so for example it should offer code lenses or code actions only if they are available in the current cursor position. But I reckon that may result in a confusing experience with items changing that much, so I'm not opposed to offering customisation for it. Out of interest though, what is it you want to customise? As in, what would want to add/remove?

maujim commented 3 years ago

I have mappings for go to definition, rename and hover because I use those often so I've removed those from the context menu.

For the rest of the functionality, I don't use those enough to warrant a dedicated mapping so I have a mapping for the context menu and I use it to access the other functionalities. I've also added code lens action and explain error at point to the context menu.

I think a "smart context menu" would be a nice feature but that it shouldn't be the default and instead be enabled by a config variable.

martskins commented 3 years ago

I see. Well, it doesn't hurt having that be configurable, so if you are happy to send a PR I'll be glad to merge. Otherwise I'll see to add this myself in the next few days.

maujim commented 3 years ago

I don't think I can send a PR anytime soon, sorry :(