vscode-cpptools
vscode-cpptools copied to clipboard
Go to Definition acts like Go to References
Have foo() declared in foo.h, defined in foo.cpp and used in main.cpp. Pressing F12 on either declaration or definition will sometimes show all references instead of going to declaration/definition.
Hi @ghuser404 I believe this behavior is coming from VS Code, not the C/C++ Extension. The extension registers 'providers' for these operations, but VS Code decides when to invoke them. Some possibly relevant VS Code issues are:
https://github.com/microsoft/vscode/issues/90012 https://github.com/microsoft/vscode/issues/85403
@Colengms Thanks for letting me know about this feature. However, there is a comment about cpptools:
Yeah, that's feature ;-) When "Go To Definition" (or its siblings like declaration, type def, etc) results the current location as result, then VS Code automatically runs an alternative command. That's by default find references (for go to def) but can be tweaked here: editor.gotoLocation.alternativeDefinitionCommand. For instance, for the cpp-tools computing references is very expensive and they contribute a new default (for cpp) which is go to declaration and vice versa.
- How does cpptools change this default? Is it configurable?
- I noticed that it only works correctly when both .h and .cpp files are open. Otherwise, it still shows the references, which is undesirable. So the cpptools's new default doesn't work consistently. To me, it seems like a bug in either vscode or cpptools.
I believe that commenter was mistaken. Extensions override defaults using a configurationDefaults section in their package.json. Ours does not contain overrides for anything under editor.gotoLocation, nor do I see any references to these setting in our code.
Related: https://github.com/microsoft/vscode-cpptools/issues/4909
@Colengms I think we wanted to override editor.gotoLocation, but we never followed up on that to investigate what the best user experience would be.
I've overridden these settings, but for some functions it still either doesn't jump to declaration, jumps to something unrelated in external code or shows references.
"editor.gotoLocation.alternativeDeclarationCommand": "editor.action.goToDefinition",
"editor.gotoLocation.alternativeDefinitionCommand": "editor.action.revealDeclaration"