Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP Code Action Source #6

Closed
axieax opened this issue Dec 15, 2021 · 12 comments
Closed

LSP Code Action Source #6

axieax opened this issue Dec 15, 2021 · 12 comments

Comments

@axieax
Copy link
Contributor

axieax commented Dec 15, 2021

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
Copy link
Owner

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
Copy link
Contributor Author

axieax commented Dec 17, 2021

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
Copy link
Owner

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

@axieax
Copy link
Contributor Author

axieax commented Dec 18, 2021

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

@axieax
Copy link
Contributor Author

axieax commented Jan 31, 2022

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
Copy link
Owner

stevearc commented Feb 1, 2022

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
Copy link
Contributor Author

axieax commented Feb 2, 2022

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
Copy link
Contributor Author

axieax commented May 27, 2022

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

@stevearc
Copy link
Owner

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
Copy link
Contributor Author

axieax commented May 30, 2022

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
Copy link
Owner

Done!

@axieax
Copy link
Contributor Author

axieax commented May 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants