-
-
Notifications
You must be signed in to change notification settings - Fork 837
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
expose lsp handler version of telescope lsp builtins #3196
Comments
Hey sorry for the late response. Can you clarify this for me? When you say
do you mean like via lspconfig (or personal config)? The servers themselves aren't setting vim lsp handlers are they?
This is actually something we've been tracking and I've briefly taken a look at a while back but didn't have any great ideas. So by using something like your
We currently merge and bind telescope.nvim/lua/telescope/builtin/init.lua Lines 542 to 593 in 79552ef
Maybe one downside to binding telescope pickers to lsp handlers is that dynamically passing telescope options would probably be not possible (eg. calling |
handlers instead of replacing the entire handler server-side refs nvim-telescope/telescope.nvim#3196
After your question I looked at my code again with fresh eyes and realized a had indeed muddied the waters between
Should have been
After taking my hands off of the So, for compatibility with otter there is nothing to be done on telescope's side anymore, though the telescope as lsp handlers implementation remains an interesting prospect. |
This issue is here to gauge interest for a PR.
Issue
Telescope ships with built-in pickers for common lsp actions such as got-to-definition and list document symbols. However, those have to be manually bound to keys and are disconnected from the nvim builtin functions like
vim.lsp.buf.definition
.As such they have to do some of the work that would already be done by the
vim.lsp.buf.<method>
functions, such as creating theparams
for the lsp request and sending the request to the buffers. Optimally, telescope would only have to inject itself into one part of the lsp workflow: the handling of the response, which can easily be configured by assigning tovim.lsp.handlers[<method>]
.I do have a secondary motif for this PR: my plugin otter.nvim acts as a language server to provide lsp features for code embedded in other code, like for example python code chunks in markdown(-based) documents or SQL queries in rust code. It does so by sending a modified request to other language servers attached to hidden buffers behind the scenes. It also brings its own handlers to modify the response before passing it on to the default Neovim handler for that type of request (
vim.lsp.handlers
):Integrating this with telescope is a common feature request (or confusion) I get. But because the current pickers send their own requests manually with
vim.lsp.buf_request
and inject their own handler, the handler specified by the language server is overwritten (The hierarchy for the handler used bybuf_request
goes: 1) explicitly set 2) handler provided by the server 3) handler provided by Neovim).Solution
One solution is to take the relevant pieces from the
telescope.builtin.__lsp
module (https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/builtin/__lsp.lua) and use it to expose a version of the picker that acts purely as a lsp response handler. I made an example implementation here: https://github.com/jmbuhr/quarto-nvim-kickstarter/blob/main/lua/misc/handlers.lua(the code is almost the same except that the handler part has been pulled out of the individual pickers).
This can then be used like such:
https://github.com/jmbuhr/quarto-nvim-kickstarter/blob/6455ad9123041f11e3294508db8f216223e2ca8a/lua/plugins/lsp.lua#L118-L122
So overall this is not only useful for integrating with other plugins, but also to remove the need for a different keybinding.
Please let me know what you think :)
Open question
My solution still has one open question: It is not currently using user-defined defaults for
opts
. Is there a way of accessing those from a normal function?The text was updated successfully, but these errors were encountered: