diff --git a/lua/lspconfig/configs/ccls.lua b/lua/lspconfig/configs/ccls.lua index 43bc8b12b8..198ae8c89b 100644 --- a/lua/lspconfig/configs/ccls.lua +++ b/lua/lspconfig/configs/ccls.lua @@ -1,5 +1,25 @@ local util = require 'lspconfig.util' +local function switch_source_header(bufnr) + bufnr = util.validate_bufnr(bufnr) + local client = util.get_active_client_by_name(bufnr, 'ccls') + local params = { uri = vim.uri_from_bufnr(bufnr) } + if client then + 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' + end +end + return { default_config = { cmd = { 'ccls' }, @@ -12,6 +32,14 @@ return { -- ccls does not support sending a null root directory single_file_support = false, }, + commands = { + CclsSwitchSourceHeader = { + function() + switch_source_header(0) + end, + description = 'Switch between source/header', + }, + }, docs = { description = [[ https://github.com/MaskRay/ccls/wiki