From ab8c557fe7a2335c8502c1728c9dba15d37d6238 Mon Sep 17 00:00:00 2001 From: Stephen Senran Zhang Date: Mon, 1 Sep 2025 14:04:48 +0800 Subject: [PATCH] Updated nvim lspconfig (markdown) --- nvim-lspconfig.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/nvim-lspconfig.md b/nvim-lspconfig.md index 3a96461..174ab15 100644 --- a/nvim-lspconfig.md +++ b/nvim-lspconfig.md @@ -1,3 +1,5 @@ +# Install + Install [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) according to the instructions in its README. has a built-in rule for ccls. @@ -13,3 +15,34 @@ lspconfig.ccls.setup { } } ``` + +# ccls extensions + +To use ccls extensions, e.g., `$ccls/inheritance`, `$ccls/member`, etc., we need some hacks. + +1. Copy `get_location` function from `nvim/runtime/lua/vim/lsp/buf.lua` to `~/.config/nvim/lua/get_location.lua`, and modify it to support custom parameters. An example can be found at [here](https://github.com/zsrkmyn/dotvim/blob/master/lua/get_location.lua), and you can directly use it. +2. In `init.lua`, add kepmaps on attach, e.g., +``` +local get_location = require'get_location' +require'lspconfig'.ccls.setup { + -- ... + on_attach = function(client, bufnr) + local opts = { buffer = bufnr, remap = false } + local lopts = { loclist = true } + -- ... + vim.keymap.set('n', 'gxb', function() get_location('$ccls/inheritance', {}, lopts) end, opts) + vim.keymap.set('n', 'gxB', function() get_location('$ccls/inheritance', {levels=3}, lopts) end, opts) + vim.keymap.set('n', 'gxd', function() get_location('$ccls/inheritance', {derived=true}, lopts) end, opts) + vim.keymap.set('n', 'gxD', function() get_location('$ccls/inheritance', {derived=true, levels=3}, lopts) end, opts) + vim.keymap.set('n', 'gxc', function() get_location('$ccls/call', {}, lopts) end, opts) + vim.keymap.set('n', 'gxC', function() get_location('$ccls/call', {callee=true}, lopts) end, opts) + vim.keymap.set('n', 'gxs', function() get_location('$ccls/member', {kind=2}, lopts) end, opts) + vim.keymap.set('n', 'gxf', function() get_location('$ccls/member', {kind=3}, lopts) end, opts) + vim.keymap.set('n', 'gxm', function() get_location('$ccls/member', {}, lopts) end, opts) + vim.keymap.set('n', '', function() get_location('$ccls/navigate', {direction='D'}, lopts) end, opts) + vim.keymap.set('n', '', function() get_location('$ccls/navigate', {direction='U'}, lopts) end, opts) + vim.keymap.set('n', '', function() get_location('$ccls/navigate', {direction='L'}, lopts) end, opts) + vim.keymap.set('n', '', function() get_location('$ccls/navigate', {direction='R'}, lopts) end, opts) + end, + -- ... +``` \ No newline at end of file