Accessing registered TestControllers #2384
-
Is there any way of accessing TestControllers other extensions have registered? I'd like to be able to display info in my extension's views about the status of some tests without totally writing my own controller from scratch, but it doesn't seem like this is supported out of the box. Do I have to hope that the implementing extension has the relevant exports? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
According to copilot, yes, accessing TestController instances registered by other extensions is not directly supported out of the box in Visual Studio Code. The TestController API is designed to be used within the context of the extension that creates it. However, there are a few approaches you can consider:
If the other extension provides an API, you can use the vscode.extensions.getExtension method to access it. This requires the other extension to explicitly export the necessary functionality. Example: const otherExtension = vscode.extensions.getExtension('publisher.extensionName');
if (otherExtension) {
const api = otherExtension.exports;
// Use the API provided by the other extension
}
Extensions can communicate via shared workspace state using vscode.workspaceState or vscode.globalState. This requires cooperation between the extensions to read/write the necessary information. // Writing state in one extension
vscode.workspaceState.update('testStatus', { /* test status data */ });
// Reading state in another extension
const testStatus = vscode.workspaceState.get('testStatus'); Let us know if any of those approaches help to get started. |
Beta Was this translation helpful? Give feedback.
I'd looked at both of those options before posting. Neither did quite what I wanted, but I found the testObserver proposed API which seems like it might accomplish what I need, and requiring an insiders build isn't a limitation in my use case.