clangd_extensions.nvim icon indicating copy to clipboard operation
clangd_extensions.nvim copied to clipboard

Feature Request: Show all overrides of a virtual method

Open SteveWolligandt opened this issue 7 months ago • 3 comments

Hi, I thought that querying a list of all overridden methods of a virtual method would be pretty nice. For example when having this code base:

class Base {
 public:
  virtual void foo() = 0;
};

class Impl1 : public Base {
 public:
  void foo() { std::cout << "In Impl1\n"; } override
};

class Impl2 : public Base {
 public:
  void foo() { std::cout << "In Impl2\n"; } override
};

When the cursor is on any foo declaration / definition and executing :ClangdShowOverrides this could open a new split in which you would get something like this:

Base::foo() 
- Impl1::foo()
- Impl2::foo()

As in :ClangdTypeHierarchy you could jump to definition by hovering any line.

Thanks, Steve

SteveWolligandt avatar Apr 02 '25 10:04 SteveWolligandt

I can think of one way to implement this: use reference container to find out the class in which the function declaration is, get its type hierarchy, ask for the ASTs of all the types in the hierarchy (the response to the typeHierarchy requests contains the location), and look at every CXXMethod in the AST to find a function which matches the name and signature.

I'm trying to think of something smarter

p00f avatar Apr 02 '25 11:04 p00f

https://neovim.io/doc/user/lsp.html#vim.lsp.buf.implementation() should accomplish this

HighCommander4 avatar Apr 04 '25 21:04 HighCommander4

I found out that this can be done with the plugin "Trouble". @HighCommander4, it is probably using what you are suggesting.

SteveWolligandt avatar May 05 '25 20:05 SteveWolligandt