nvim-config

Log | Files | Refs | Submodules | README

commit 906fd9e03d71cb761bf9198187422a0ef52c44b1
parent 44a79746619eff8f398378be3fefce788f20232f
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Tue, 26 Jul 2022 15:49:19 +0200

feat(c): correctly map clangd switch source header

Diffstat:
Aafter/ftplugin/c.lua | 33+++++++++++++++++++++++++++++++++
Dafter/ftplugin/c.vim | 16----------------
2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/after/ftplugin/c.lua b/after/ftplugin/c.lua @@ -0,0 +1,33 @@ +vim.opt_local.expandtab = true +vim.opt_local.textwidth = 80 +vim.opt_local.tabstop = 2 +vim.opt_local.foldmethod = "expr" +vim.opt_local.foldexpr = "nvim_treesitter#foldexpr()" +vim.opt_local.foldlevel = 0 +vim.opt_local.comments:prepend(":///") +vim.opt_local.commentstring = "//%s" + +-- if !empty(findfile('src/uncrustify.cfg', ';')) && executable("uncrustify") +-- setlocal formatprg=uncrustify\ -q\ -l\ C\ -c\ src/uncrustify.cfg\ --no-backup +-- endif + +vim.keymap.set("n", "<Leader><Leader>", function() + local bufnr = vim.api.nvim_get_current_buf() + local clangd_client = vim.lsp.get_active_clients { bufnr = bufnr, name = 'clangd' }[1] + local params = { uri = vim.uri_from_bufnr(bufnr) } + if clangd_client then + clangd_client.request('textDocument/switchSourceHeader', params, function(err, result) + if err then + return + end + if not result then + print 'Corresponding file cannot be determined' + return + end + vim.cmd.edit(vim.uri_to_fname(result)) + end, bufnr) + end +end, + { + buffer = true, + }) diff --git a/after/ftplugin/c.vim b/after/ftplugin/c.vim @@ -1,16 +0,0 @@ -" Last Change: 2022 Jul 20 - -setlocal expandtab -setlocal textwidth=80 " Nvim uses this -setlocal tabstop=2 -setlocal foldmethod=expr -setlocal foldexpr=nvim_treesitter#foldexpr() -setlocal foldlevel=0 -setlocal comments^=:/// -setlocal commentstring=//%s - -if !empty(findfile('src/uncrustify.cfg', ';')) && executable("uncrustify") - setlocal formatprg=uncrustify\ -q\ -l\ C\ -c\ src/uncrustify.cfg\ --no-backup -endif - -nnoremap <buffer> <Leader><Leader> <cmd>ClangdSwitchSourceHeader<CR>