From 9194d0e863f9c8970021b23cf48685cfda289d07 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 1 Jan 2025 21:25:52 -0800 Subject: feat(ccls): add CclsSwitchSourceHeader (#3535) * feat(ccls): add CclsSwitchSourceHeader ccls 0.20241108 has added support for the extension from clangd. --------- Co-authored-by: glepnir --- lua/lspconfig/configs/ccls.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lua') diff --git a/lua/lspconfig/configs/ccls.lua b/lua/lspconfig/configs/ccls.lua index 43bc8b12..1f0e937d 100644 --- a/lua/lspconfig/configs/ccls.lua +++ b/lua/lspconfig/configs/ccls.lua @@ -1,5 +1,24 @@ 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') + if not client then + vim.notify('method textdocument/switchsourceheader is not supported by any servers active on the current buffer') + end + local params = vim.lsp.util.make_text_document_params(bufnr) + client.request('textdocument/switchsourceheader', 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 + return { default_config = { cmd = { 'ccls' }, @@ -12,6 +31,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 -- cgit v1.2.3-70-g09d2