My primary entrypoint containing the activate() function is:
extension.ts
import * as vscode from "vscode";
import { subscribe } from "./eventListeners.ts";
export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("mycommand.activate", () => {});
subscribe(vscode);
context.subscriptions.push(t);
}
I decided to separate event subscription into its own file:
eventListeners.ts
import * as vscode from "vscode";
type VSCode = typeof vscode;
export function subscribe(vscode: VSCode) {
...
}
When creating the separate file, my intentions were:
- To provide the vscode instance as an argument. This seems necessary due to the unique way vscode processes commands from the activate() function.
- To ensure type safety in my code. Hence, the inclusion of
type VSCode = typeof vscode;
.
Queries:
- Is there a more efficient method for separating event subscription into another file without passing in the vscode instance?
- Is there a better approach for importing types in the distinct file?