diff options
Diffstat (limited to 'lua/lspconfig/server_configurations/clangd.lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/clangd.lua | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/lua/lspconfig/server_configurations/clangd.lua b/lua/lspconfig/server_configurations/clangd.lua index 08cf307a..cda6ef43 100644 --- a/lua/lspconfig/server_configurations/clangd.lua +++ b/lua/lspconfig/server_configurations/clangd.lua @@ -3,22 +3,27 @@ local util = require 'lspconfig.util' -- https://clangd.llvm.org/extensions.html#switch-between-sourceheader local function switch_source_header(bufnr) bufnr = util.validate_bufnr(bufnr) + local clangd_client = util.get_active_client_by_name(bufnr, 'clangd') local params = { uri = vim.uri_from_bufnr(bufnr) } - vim.lsp.buf_request( - bufnr, - 'textDocument/switchSourceHeader', - params, - util.compat_handler(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) - ) + if clangd_client then + clangd_client.request( + 'textDocument/switchSourceHeader', + params, + util.compat_handler(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' + end end local root_pattern = util.root_pattern('compile_commands.json', 'compile_flags.txt', '.git') |
