在 VSCode 扩展中找不到命令 [英] Command not found in VSCode extension

查看:79
本文介绍了在 VSCode 扩展中找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 VSCode 扩展.这个扩展提供了两个命令,不用管它们的实现:

I am trying to create a VSCode extension. This extension provides two commands, never mind their implementation:

export function activate(context: ExtensionContext) {

    const provider = new ContentProvider();
    const providerRegistrations = Disposable.from(
        workspace.registerTextDocumentContentProvider(ContentProvider.scheme, provider)
    );

    // Open the dynamic document, and shows it in the next editor
    const openMyExtensionCommandRegistration = commands.registerTextEditorCommand('extension.openMyExtension', editor => {
        // Activate the extension and do something
    });

    const useMyExtensionCommandRegistration = commands.registerTextEditorCommand('extension.useMyExtension', editor => {
        // Do something
    });

    context.subscriptions.push(
        provider,
        openMyExtensionCommandRegistration,
        useMyExtensionCommandRegistration,
        providerRegistrations
    );
}

这是我的 package.json 文件的一部分:

And this is a part of my package.json file:

"activationEvents": [
        "onCommand:extension.openMyExtension"
    ],
    "main": "./out/extension",
    "contributes": {
        "commands": [
            {
                "command": "extension.openMyExtension",
                "title": "Open my extension",
                "category": "MyExtension"
            },
            {
                "command": "extension.useMyExtension",
                "title": "Do something with my extension",
                "category": "MyExtension"
            }
        ],

应该激活我的扩展程序的第一个命令有效.它出现在命令面板中,并且在调用时实际执行它应该执行的操作.

The first command, which is supposed to activates my extension, works. It appears in the command palette, and actually does what it is supposed to do when invoked.

然而,尽管出现在命令面板中,但第二个命令在调用时会引发以下错误消息:

The second command however, despite appearing in the command palette, raise the following error message when called:

找不到命令extension.useMyExtension"

我觉得奇怪的是,我的第一个命令可以正常工作,但第二个命令却不能,因为代码非常相似.任何想法为什么?

I find it weird that my first command works fine but not the second since the code is quite similar. Any ideas why?

请注意,我显然更改了一些变量名称,我仔细检查了实际代码中的拼写错误.

推荐答案

由于我的评论对某人有所帮助,因此我想将其发布为答案以提高其知名度:

Since my comment helped someone, I would like to post it as an answer to give it more visibility:

我能够通过手动编译 Typescript 源(通过将 tsc -p ./ 运行到我的根文件夹中)来解决这个问题.调试时应该会自动运行这个命令,但是我仍然无法找到为什么在我的机器上不是这种情况.

I was able to fix this issue by manually compiling the Typescript source (by running tsc -p ./ into my root folder). This command should be ran automatically when debugging, however, I was still not able to find why it was not the case on my machine.

这篇关于在 VSCode 扩展中找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆