Vscode-cpptools: Goto definition on scoped functions does not perform goto declaration alternate command

Created on 29 Jan 2020  Â·  6Comments  Â·  Source: microsoft/vscode-cpptools

Whenever I click Go to Definition/Declaration for a function, the Go to References operation occurs.

Go to Definition Language Service Visual Studio Code bug

Most helpful comment

setting editor.action.revealDeclaration as the alternate definition command seems to work for this issue. I'm not sure what editor.action.goToDeclaration is supposed to do or why it doesn't work for this case.

All 6 comments

This is "by design" from recent VS Code changes. You can configure it via the settings editor.gotoLocation.alternativeDeclarationCommand and alternativeDefinitionCommand which default to editor.action.goToReferences.

However, maybe our C/C++ extension could overwrite these defaults if they're not good defaults for C/C++, so we can use this issue to track possibly changing those defaults.

I also find this change to be unintuitive. I used to be able to Control + Click on a declaration/definition of a method to be able to cycle between the two. Now when I Control + Click on the definition it starts trying to do a peek of find all references. I just tried changing editor.gotoLocation.alternativeDefinitionCommand to be editor.action.goToDeclaration but that doesn't seem to work. Any ideas?

Yeah, you're right, setting that doesn't work. According to the comment at https://github.com/microsoft/vscode/issues/73081#issuecomment-557491699 it's supposed to. Do you want to file a bug on VS Code? Otherwise, I could file the bug myself.

It appears to work for non-scoped functions, but definitions with a scope (i.e. class methods) don't work. The "goes to the same location" logic is probably broken in that case. It's possible the VS Code team could say our extension is to blame (not sure yet)…we return the same range data we always have.

Yeah, I forgot about the Ctrl+Click scenario -- that seems like the main reason to have this improved/fixed, since the right-click command can be worked around via selecting the Go to Declaration on the Definition and Go to Declaration on the definition to cycle.

Possibly related: #4871

setting editor.action.revealDeclaration as the alternate definition command seems to work for this issue. I'm not sure what editor.action.goToDeclaration is supposed to do or why it doesn't work for this case.

Was this page helpful?
0 / 5 - 0 ratings