From 3347d5e1fd1173d86295d735f4acffd6fa88ecb2 Mon Sep 17 00:00:00 2001 From: Shatur95 Date: Thu, 4 Jun 2020 13:26:28 +0300 Subject: Add clangd switch source header command --- lua/nvim_lsp/clangd.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lua') 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 -- cgit v1.2.3-70-g09d2