Cannot return a ouput for go to definition when running as vscode command but can go to definition use UI
Environment
- OS and Version: Mac
- VS Code Version: 1.86.0
- C/C++ Extension Version: v1.18.5
- If using SSH remote, specify OS of remote machine: Linux Ubuntu
Bug Summary and Steps to Reproduce
Bug Summary: I can use go to definition from ui side. but when I try to develop an extension and try to use "vscode.executeDefinitionProvider" to get the definition via "vscode.commands.executeCommand", it gives me nothing. However "vscode.executeReferenceProvider" works. Expected behavior: I should also get the output for "vscode.executeDefinitionProvider" command
Configuration and Logs
default way. I did not change these file after I download the extension
Other Extensions
No response
Additional context
sample file
#include
// Function definition int addNumbers(int a, int b, int c) { return a + b; }
int main() { int num1 = 5; int num2 = 7;
// Calling the function and storing the result
int sum = addNumbers(num1, num2);
// Printing the result
cout << "The sum of " << num1 << " and " << num2 << " is " << sum << "." << endl;
return 0;
} and We use addNumbers to test it.
Just to clarify are you saying that you cannot use the go to definition command to navigate to the addNumbers function within the same .cpp file?
If so, I have not been able to reproduce the issue you are having.
Thanks for the help. I am saying when I use the ui goes to definition(F12) it can. But I am developing an extension and when I use vscode.executeDefinitionProvider to get the location/location link in typescript, it gives me nothing. The code is
vscode.commands.executeCommandArray<vscode.LocationLink | vscode.Location>
>("vscode.executeDefinitionProvider", document.uri, range.start);
This returns me nothing but I can use definition(F12) on editor
After further investigation, it looks like go to def is actually dependent on information from seeing the file open and certain database information that may not be available at the time you are calling go to def. Could you provide the logging output from the extension when you perform this operation?
Currently there is no way around the current dependencies and if the information is not available when you want we would have to add future support for it.
but when i use executeReferenceProvider, it can give me the information. Could that be intellisense does not define a definition provider and on vscode if you use F12, it also goes to reference?
Thank you for letting us know about your issue, after investigating further a fix should be out the in the next pre-release version of the extension (1.19.3)
This should be addressed in 1.19.4.