p00f / clangd_extensions.nvim

Clangd's off-spec features for neovim's LSP client. Use https://sr.ht/~p00f/clangd_extensions.nvim instead
MIT License
495 stars 18 forks source link

Type hierarchy symbol navigation #36

Closed hongxuchen closed 1 year ago

hongxuchen commented 1 year ago

For now, this plugin directly calls what clangd server provides and render results in nvim's buffers. In particular, it provides ClangdTypeHierarchy command which shows the parent and child types of the symbol under cursor when the symbol corresponds a C++ type, in a separated buffer.

Unfortunately, it seems clangd itself does not provide the position information of the the parent and child types; thus it cannot be used for code navigation. Is it possible to combine a few requests to (patially) achieve this goal? For example, in the separated buffer of ClangdTypeHierarchy command, clangd_extensions.nvim asynchronously invoke vim.lsp.buf.workspace_symbol (or telescope.builtin.lsp_workspace_symbols if present) to additionally request the symbol under the cursor and filter with type definition like struct/class, etc. Indeed it is a hack, but I think this would be quite useful for me.

p00f commented 1 year ago

Sounds like a nice idea - I don't have time to implement this right now, but I can look at a PR

hongxuchen commented 1 year ago

My neovim/lua kungfu is not powerful enough right now but I will try when I can 😄

Just now I noticed that there seems no need for a hack, Clangd's typeHierarchy/resolve response already contains the position info (uri, range and selectionRange).

p00f commented 1 year ago

Ah thanks, I'll look at it in some time

p00f commented 1 year ago

Implemented in 7f003d48d2b846aeb364d153d7defc7e3cea42bd