diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim_lsp/clangd.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lua/nvim_lsp/clangd.lua b/lua/nvim_lsp/clangd.lua index 24b8f2c8..815d3b32 100644 --- a/lua/nvim_lsp/clangd.lua +++ b/lua/nvim_lsp/clangd.lua @@ -1,6 +1,16 @@ local configs = require 'nvim_lsp/configs' local util = require 'nvim_lsp/util' +local function switch_source_header(bufnr) + bufnr = util.validate_bufnr(bufnr) + local params = { uri = vim.uri_from_bufnr(bufnr) } + vim.lsp.buf_request(bufnr, 'textDocument/switchSourceHeader', params, function(err, _, result) + if err then error(tostring(err)) end + if not result then print ("Corresponding file can’t be determined") return end + vim.api.nvim_command('edit '..vim.uri_to_fname(result)) + end) +end + local root_pattern = util.root_pattern("compile_commands.json", "compile_flags.txt", ".git") configs.clangd = { default_config = util.utf8_config { @@ -12,6 +22,14 @@ configs.clangd = { return root_pattern(filename) or util.path.dirname(filename) end; }; + commands = { + ClangdSwitchSourceHeader = { + function() + switch_source_header(0) + end; + description = "Switch between source/header"; + }; + }; docs = { description = [[ https://clang.llvm.org/extra/clangd/Installation.html @@ -28,4 +46,6 @@ as compile_commands.json or, for simpler projects, a compile_flags.txt. }; }; } + +configs.clangd.switch_source_header = switch_source_header -- vim:et ts=2 sw=2 |
