mirror of
https://github.com/neovim/nvim-lspconfig
synced 2024-09-16 14:24:07 +02:00
feat(clangd): add symbolInfo support (#3274)
* feat(clangd): add symbolInfo support Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com> * fix(clangd): use make_position_params util function Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com> * fix(clangd): no need to use a parameter Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com> * fix(clangd): remove parameter from command Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com> * fix(clangd): check if client supports method Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com> * fix(clangd): use client request instead of buf_request Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com> --------- Signed-off-by: Dimitris Dimitropoulos <dimitris.dimitropoulos00@gmail.com>
This commit is contained in:
parent
20906fce85
commit
63ee95e052
1 changed files with 31 additions and 0 deletions
|
@ -21,6 +21,31 @@ local function switch_source_header(bufnr)
|
|||
end
|
||||
end
|
||||
|
||||
local function symbol_info()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local clangd_client = util.get_active_client_by_name(bufnr, 'clangd')
|
||||
if not clangd_client or not clangd_client.supports_method 'textDocument/symbolInfo' then
|
||||
return vim.notify('Clangd client not found', vim.log.levels.ERROR)
|
||||
end
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
clangd_client.request('textDocument/symbolInfo', params, function(err, res)
|
||||
if err or #res == 0 then
|
||||
-- Clangd always returns an error, there is not reason to parse it
|
||||
return
|
||||
end
|
||||
local container = string.format('container: %s', res[1].containerName) ---@type string
|
||||
local name = string.format('name: %s', res[1].name) ---@type string
|
||||
vim.lsp.util.open_floating_preview({ name, container }, '', {
|
||||
height = 2,
|
||||
width = math.max(string.len(name), string.len(container)),
|
||||
focusable = false,
|
||||
focus = false,
|
||||
border = require('lspconfig.ui.windows').default_options.border or 'single',
|
||||
title = 'Symbol Info',
|
||||
})
|
||||
end, bufnr)
|
||||
end
|
||||
|
||||
local root_files = {
|
||||
'.clangd',
|
||||
'.clang-tidy',
|
||||
|
@ -56,6 +81,12 @@ return {
|
|||
end,
|
||||
description = 'Switch between source/header',
|
||||
},
|
||||
ClangdShowSymbolInfo = {
|
||||
function()
|
||||
symbol_info()
|
||||
end,
|
||||
description = 'Show symbol info',
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
|
|
Loading…
Reference in a new issue