clangd/vscode-clangd

Incorrect results about Go-to-definition and Go-to-declaration

tisble opened this issue · 3 comments

Hi, I found a bug about the go to definition and go to declaration. Please see the code example below:

#include  <stdio.h>
struct str {
    int v;
};
int main() {
    str s;
    s.v = 10;
    return 0;
}

I performed Go-to-def/decl on the variable s in declaration statement at line 6, but it jumps to the variable s at line 7. Actually, I think this is Go to Use or Find References, rather than Go-to-def or decl (should be unchanged at line 6). So, this is a bug.

System information

Clangd version:
Apple clangd version 15.0.0 (clang-1500.3.9.4)
Features: mac+xpc
Platform: x86_64-apple-darwin23.5.0; target=arm64-apple-darwin23.5.0

clangd extension version: Version 0.1.28: March 20, 2024

Operating system: MacOS

It looks like the client sides a textDocument/references request if the response to textDocument/definition was the same location as the input.

This is a behaviour of the vscode-languageclient component that lives upstream at https://github.com/Microsoft/vscode-languageserver-node/, could you file an issue there please?

Hi, I have submitted the issue and the link is: microsoft/vscode-languageserver-node#1486

This is a behaviour of the vscode-languageclient component

It turns out I was mistaken about this: this is actually a behaviour of vscode itself.

Moreover, it is configurable as follows:

  1. Open vscode settings
  2. Search for the setting name editor.gotoLocation.alternativeDefinitionCommand. Note the setting's description: "Alternative command id that is being executed when the result of 'Go to Definition' is the current location.", and default value, editor.action.goToReferences.
  3. Change the setting value in the dropdown to empty.

Now, go-to-def on s on line 6 will leave the cursor at the same location.