diff options
| author | glepnir <glephunter@gmail.com> | 2025-01-02 15:26:38 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-02 15:26:38 +0800 |
| commit | 88c4c042e1e59f992e4c7aff3531033047b3aa9c (patch) | |
| tree | 4e0c7e7691f223a1895e3bf58eae7c5b20cd0886 /lua | |
| parent | fix(ccls): typo on request method (#3536) (diff) | |
| download | nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.tar nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.tar.gz nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.tar.bz2 nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.tar.lz nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.tar.xz nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.tar.zst nvim-lspconfig-88c4c042e1e59f992e4c7aff3531033047b3aa9c.zip | |
refactor(clangd): imporve switchsourceheader handler (#3537)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/configs/ccls.lua | 5 | ||||
| -rw-r--r-- | lua/lspconfig/configs/clangd.lua | 30 |
2 files changed, 18 insertions, 17 deletions
diff --git a/lua/lspconfig/configs/ccls.lua b/lua/lspconfig/configs/ccls.lua index 9583fcb0..e64df3c6 100644 --- a/lua/lspconfig/configs/ccls.lua +++ b/lua/lspconfig/configs/ccls.lua @@ -1,13 +1,14 @@ local util = require 'lspconfig.util' local function switch_source_header(bufnr) + local method_name = 'textDocument/switchSourceHeader' bufnr = util.validate_bufnr(bufnr) local client = util.get_active_client_by_name(bufnr, 'ccls') if not client then - vim.notify('method textdocument/switchsourceheader is not supported by any servers active on the current buffer') + return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name)) end local params = vim.lsp.util.make_text_document_params(bufnr) - client.request('textDocument/switchsourceheader', params, function(err, result) + client.request(method_name, params, function(err, result) if err then error(tostring(err)) end diff --git a/lua/lspconfig/configs/clangd.lua b/lua/lspconfig/configs/clangd.lua index 20acc127..f85337fa 100644 --- a/lua/lspconfig/configs/clangd.lua +++ b/lua/lspconfig/configs/clangd.lua @@ -2,23 +2,23 @@ local util = require 'lspconfig.util' -- https://clangd.llvm.org/extensions.html#switch-between-sourceheader local function switch_source_header(bufnr) + local method_name = 'textDocument/switchSourceHeader' bufnr = util.validate_bufnr(bufnr) - local clangd_client = util.get_active_client_by_name(bufnr, 'clangd') - local params = { uri = vim.uri_from_bufnr(bufnr) } - if clangd_client then - clangd_client.request('textDocument/switchSourceHeader', params, function(err, result) - if err then - error(tostring(err)) - end - if not result then - print 'Corresponding file cannot be determined' - return - end - vim.api.nvim_command('edit ' .. vim.uri_to_fname(result)) - end, bufnr) - else - print 'method textDocument/switchSourceHeader is not supported by any servers active on the current buffer' + local client = util.get_active_client_by_name(bufnr, 'ccls') + if not client then + return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name)) end + local params = vim.lsp.util.make_text_document_params(bufnr) + client.request(method_name, params, function(err, result) + if err then + error(tostring(err)) + end + if not result then + vim.notify('corresponding file cannot be determined') + return + end + vim.cmd.edit(vim.uri_to_fname(result)) + end, bufnr) end local function symbol_info() |
