stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.73k stars 32 forks source link

LSP Code Action Source #6

Closed axieax closed 2 years ago

axieax commented 2 years ago

Hello, Just wondering if there is a way to include code action source names with vim.lsp.buf.code_action(), similar to Telescope's builtin lsp_code_actions.

vim-ui-select (with dressing.nvim) image

Telescope image

stevearc commented 2 years ago

At the moment, no. The display of lines is specified by the opts.format_item function that is passed in by the caller of vim.ui.select. In this case, it's specified here.

There are some different directions I could go from here. It would be fairly straightforward to add a special_format option to the config that lets you pass in a function that overrides format_item for a specific select kind (e.g. opts.kind == 'codeaction'). That would be enough to display the client name, but it wouldn't get you the nice highlighting or column alignment.

I could go further and build out the API to let you specify highlighting and column alignment as well, but then I have to make sure that it works (or at least behaves) across all the potential backends. It adds quite a bit of code complexity and diverges from the core API, so I'm hesitant to do it without good motivation.

I think the better way to go about it would be to make the case in Neovim core to officially add columns/highlighting to the vim.ui.select API. If something like that were standardized, I'd be way happier about implementing it.

Thoughts?

axieax commented 2 years ago

Hi thanks for your detailed response. I reckon before Neovim updates their core API, the best approach right now would be to override the format item.

stevearc commented 2 years ago

Added a config option and also some example code in the help docs that should do what you want

axieax commented 2 years ago

Looks good thank you! Love how you can also filter by language server now :))

axieax commented 2 years ago

Hi @stevearc, just wondering, but is it possible to link the [LANGUAGE_SERVER] to the Comment highlight group? This would be amazing if possible :D

stevearc commented 2 years ago

Unfortunately, this isn't possible without a lot of additional hacks. Dressing is just trying to provide a good, easy replacement for vim.ui.select to improve the UI for general use cases. I could add customizations for specific use cases (like code actions) that improves the UI a bit, but that's not what I want this project to become. Besides, as you mentioned, someone has already done that work! You can already use the Telescope code action picker instead of vim.lsp.buf.code_action(). Anything I did to mimic that UI in dressing would basically amount to copy/pasting that code in anyway, so better to just use it directly!

axieax commented 2 years ago

Yeah fair enough thanks for the clarification. Sometimes it's quite annoying that Telescope's code action doesn't do everything vim.lsp.buf.code_action would do (esp for nvim-jdtls), so I have to switch between both conditionally based on filetype. But yeah, perhaps I'll have a look into creating my own Telescope picker. Thanks again!

axieax commented 2 years ago

Hi, just wondering if this can now be achieved with e607dd99aeb5ce21e9a3d8f4c028650db12bd3af

stevearc commented 2 years ago

That commit was more intended for a different use case altogether, but it does technically unlock more UI customization abilities for end users as well (via the get_config override).

In this case though, I think I'm going to go back on my previous decision. I was stuck on trying to figure out how to keep the UI consistent across all of the backends, but (especially with that recent change) I don't think that's a hard requirement anymore. I'm more on board with small amounts of customization in certain circumstances for common or core neovim features.

So I've gone ahead and added a custom formatter when kind = 'codeaction'. Let me know if it works for you!

axieax commented 2 years ago

Thanks I love the change! Is it possible to search through the language server names (comment) as well?

Glad to see this implemented now - which means I don't need https://github.com/nvim-telescope/telescope-ui-select.nvim anymore :D

stevearc commented 2 years ago

Done!

axieax commented 2 years ago

Thank you so much for the quick changes. Love your work as always!