Skip to content

Commit

Permalink
refactor(clangd): imporve switchsourceheader handler (#3537)
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir authored Jan 2, 2025
1 parent 709e3e8 commit 88c4c04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
5 changes: 3 additions & 2 deletions lua/lspconfig/configs/ccls.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 15 additions & 15 deletions lua/lspconfig/configs/clangd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 88c4c04

Please sign in to comment.