对于驻留activate()函数的主入口点:
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);
}我已经将事件订阅拆分为一个单独的文件:
eventListeners.ts
import * as vscode from "vscode";
type VSCode = typeof vscode;
export function subscribe(vscode: VSCode) {
...
}在另一份文件中,我想我会:
vscode.commands.registerCommand,但在执行命令之前不会运行其他命令时,一定会发生一些神奇的事情。type VSCode = typeof vscode;在那里。问题:
发布于 2022-04-07 10:22:18
添加命令作为贡献已经让VSCode知道了该命令,并将其显示在命令列表中。
但是,如果您唯一的激活事件是在运行命令时发生的。,那么在尝试使用该命令之前不会运行activate()。因此,直到第一次运行时,才会注册该命令的实际操作。
我想这就是让你困惑的原因。您可以看到这个命令,因此您认为vscode.commands.registerCommand()已经运行,因此不知道为什么activate()的其他部分没有运行。但它还没有真正运行过。
您可以尝试使用onStartupFinished作为激活事件。
关于vscode在eventListeners.ts中的使用,只需使用import * as vscode from 'vscode'。没必要把它传过来。
https://stackoverflow.com/questions/71771486
复制相似问题