问题
I am writing a Go adapter extension for the Test Explorer extension for Visual Studio Code. My extension uses language services from Microsoft's Go extension:
const symbols = await vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', uri)
However, I have an issue. When I specify extensionDependencies
and activationEvents
correctly (in package.json), symbols don't initially load (the command returns undefined
). If I set activationEvents
to *
or if I delay for long enough in my activate handler, symbols load. I thought about retrying until the command returns something, but "this file has no symbols" and "there is no symbol provider for this type of document" both return undefined
.
Is there a way to delay until a symbol provider has been defined for a specific file extension/language? Waiting for the Go extension to be activated is not enough. I would use GoDocumentSymbolProvider
directly, but the extension doesn't export anything.
回答1:
It looks like it will be possible to add a delay time before your extension is activated. See https://github.com/microsoft/vscode/issues/98083 (Add support to eventually activate an extension on startup). And https://github.com/microsoft/vscode/issues/98990 (Delayed startup activation events).
Will be in v1.46. From v1.46 release notes onStartupFinished activation event:
We now have a new activation event, similar to the already existing * activation event. The new
onStartupFinished
activation event should be used when an extension wishes to be activated sometime soon after VS Code startup, but not as part of the startup.
However, it is just a hard-coded delay, not based on other events but may still help your situation.
There is a new activation event which looks like e.g.
onStartup:1000
oronStartup:5000
. This means that the extension wants to be activated 1000ms or 5000ms after startup. This is very similar to * activation, but the extension indicates that it can wait a bit.
来源:https://stackoverflow.com/questions/60982109/wait-until-a-symbol-provider-is-available