You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Other extensions you installed (and if the issue persists after disabling them):
Does this issue involve using SSH remote to run the extension on a remote machine?: No
I am developing a vscode extension, using the vscode's built-in vscode.executeDefinitionProvider to get the definition (file path) of an include directive, using the cpptools as the language server. I found out that a call to vscode.executeDefinitionProvider would fail if the uri of a document is not displayed in a window, not even after vscode.workspace.openTextDocument but it must be opened in a window after a call to vscode.window.showTextDocument. Previously I raised this issue in vscode's repo and the maintainer told me to forward it here
Steps to reproduce
functiongetDefinition(uri: vscode.Uri,position: vscode.Position){returnvscode.commands.executeCommand("vscode.executeDefinitionProvider",uri,position)asThenable<(vscode.Location|vscode.LocationLink)[]>;}functiongetCurrentUri(){returnvscode.window.activeTextEditor?.document.uri;}functiongetFileUri(definition: (vscode.Location|vscode.LocationLink)[]){return(definition[0]asvscode.Location).uri;}asyncfunctiontestGood(){consturi=getCurrentUri()!;constpos=newvscode.Position(0,10);//the position of an include statementconstincludeDefinition=awaitgetDefinition(uri,pos);//ok, but returns a bad vscode.Location, which contains a bad vscode.Uriconsturi2=getFileUri(includeDefinition);constpos2=newvscode.Position(8,10);//the position of another include statement in the file denoted as "uri2", which is not opened yetvscode.workspace.openTextDocument(uri2).then(asyncdoc=>//"uri2" is opened{vscode.window.showTextDocument(doc).then(async()=>//"uri2" is shown in a window{constdefinition2=awaitcommands.definitionProvider(doc.uri,pos2);//SUCCESS});});}asyncfunctiontestBad(){consturi=getCurrentUri()!;constpos=newvscode.Position(0,10);//the position of an include statementconstincludeDefinition=awaitgetDefinition(uri,pos);//ok, but returns a bad vscode.Location, which contains a bad vscode.Uriconsturi2=getFileUri(includeDefinition);constpos2=newvscode.Position(8,10);//the position of another include statement in the file denoted as "uri2", which is not opened yet//directly using the uri2 to getDefinition() would fail like mentioned in #118085, but open it then get the uri property would results in a good urivscode.workspace.openTextDocument(uri2).then(asyncdoc=>//"uri2" is opened but not shown in a window{constdefinition2=awaitgetDefinition(doc.uri,pos2);//STILL FAILS HERE});}
Test this extension with a random C++ file. I hard coded the vscode.Position() in the code for testing purpose, but you can change it to whatever position.
The definition2 of testGood() function will returns a good result like this
Yeah, this is "by design". See the comment and code at https://github.com/microsoft/vscode-cpptools/blob/main/Extension/src/LanguageServer/protocolFilter.ts#L69 . We intentionally avoid sending a didOpen to cpptools unless a window is visible to avoid creating a TU when a hover is done. If you wanted to override that, you'd have to add some way to force the didOpen to be sent. Our Go to Definition implementation relies on having didOpen be called.
@sean-mcmanus Thanks for that clarification. The code seems to show even after the open document event is fired, it still checks whether the document is actually opened as one visible tab first. So I suppose it is impossible to get definition in the background?
It's not impossible...it would just require changes to our extension's code (open source TypeScript) and it would need to be done in some way that doesn't negatively affect performance too much for users who aren't using the background Go to Definition feature. Our implementation of Find All References essentially does a lot of Go to Definitions in the background without a document open.
Type: LanguageService
Describe the bug
I am developing a vscode extension, using the vscode's built-in
vscode.executeDefinitionProvider
to get the definition (file path) of an include directive, using the cpptools as the language server. I found out that a call tovscode.executeDefinitionProvider
would fail if the uri of a document is not displayed in a window, not even aftervscode.workspace.openTextDocument
but it must be opened in a window after a call tovscode.window.showTextDocument
. Previously I raised this issue in vscode's repo and the maintainer told me to forward it hereSteps to reproduce
Test this extension with a random C++ file. I hard coded the
vscode.Position()
in the code for testing purpose, but you can change it to whatever position.The
definition2
oftestGood()
function will returns a good result like thisBut the
testBad()
function returns an empty array of definition.Expected behavior
testBad()
should return the same result astestGood()
.The text was updated successfully, but these errors were encountered: