vim-lsp icon indicating copy to clipboard operation
vim-lsp copied to clipboard

Why :LspDeclaration and :LspDefinition go to the same place?

Open ComeOrDream opened this issue 2 months ago • 1 comments

I am using vim-lsp and clangd to edit my C++ program.

When searching the definition of a member function of a class, :LspDeclaration and :LspDefinition go to the declaration of the member function. How can i go to the definition of the function?

ComeOrDream avatar Oct 13 '25 11:10 ComeOrDream

#include <iostream>

class A {
public:
  A() {}

  void foo(); // LspDeclaration
};

void A::foo() { // LspDefinition
  std::cout << "Hello, World!" << std::endl;
}



int main() {
  A a;
  a.foo(); // Current cursor line
  return 0;
}

:LspDeclaration: Should jump to the declaration of foo(), which is the forward declaration inside the class A block: void foo();. :LspDefinition: Should jump to the definition (implementation) of foo(), which is the full function body: void A::foo() { std::cout << "Hello, World!" << std::endl; }.

mattn avatar Oct 13 '25 12:10 mattn