vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Cannot return a ouput for go to definition when running as vscode command but can go to definition use UI

Open zch-cc opened this issue 2 years ago • 5 comments

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 using namespace std;

// 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.

zch-cc avatar Feb 06 '24 04:02 zch-cc

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.

browntarik avatar Feb 06 '24 19:02 browntarik

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

zch-cc avatar Feb 06 '24 20:02 zch-cc

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.

browntarik avatar Feb 07 '24 20:02 browntarik

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?

zch-cc avatar Feb 08 '24 20:02 zch-cc

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)

browntarik avatar Feb 09 '24 22:02 browntarik

This should be addressed in 1.19.4.

Colengms avatar Feb 22 '24 03:02 Colengms