VSCode扩展:找不到该命令的处理程序:'sd.edit'

时间:2015-12-16 00:07:29

标签: visual-studio-code vscode-extensions

我正在进行扩展,并且可以在调试器中愉快地测试它!但是,在我将扩展打包并手动安装后,当我尝试运行命令时,它会给我一个错误:

  

找不到该命令的处理程序:'sd.edit'(或其他适用的命令,sd.edit是我为此测试的那个)

这是我的extension.ts

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'; 
import * as sd from './sd';
import * as fileutil from './fileutil';
import * as indicator from './sdIndicator';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

    let sdIndicator = new indicator.SdIndicator();
    context.subscriptions.push(sdIndicator); 

    // The command has been defined in the package.json file
    // Now provide the implementation of the command with  registerCommand
    // The commandId parameter must match the command field in package.json
    var editCommand = vscode.commands.registerCommand('sd.edit', () => {
        let sdWrapper = new sd.SdWrapper();
        sdWrapper.Edit(vscode.window.activeTextEditor.document.fileName);
        sdIndicator.UpdateStatusBar();
    });

    context.subscriptions.push(editCommand);

    var sdRevert = vscode.commands.registerCommand('sd.revert', () => {
        let sdWrapper = new sd.SdWrapper();
        sdWrapper.Revert(vscode.window.activeTextEditor.document.fileName);
        sdIndicator.UpdateStatusBar();
    });

    context.subscriptions.push(sdRevert);
}

和定义命令的package.json

{
    "name": "vscode-sd",
    "displayName": "sd",
    "description": "SD integration with vscode",
    "version": "0.0.1",
    "publisher": "ryzngard",
    "engines": {
        "vscode": "^0.10.1"
    },
    "categories": [
        "Other"
    ],
    "activationEvents": [
        "*"
    ],
    "main": "./out/src/extension",
    "contributes": {
        "commands": [
            {
                "command": "sd.edit",
                "title": "SD Edit File"
            },
            {
                "command": "sd.revert",
                "title": "SD Revert File"
            }]
    },
    "scripts": {
        "vscode:prepublish": "node ./node_modules/vscode/bin/compile",
        "compile": "node ./node_modules/vscode/bin/compile -watch -p ./"
    },
    "devDependencies": {
        "typescript": "^1.6.2",
        "vscode": "0.10.x"
    }
}

对我来说,没有什么不合适的地方,而且调试扩展程序的工作原理看起来很奇怪。有什么方法可以调试已安装的扩展?还有其他我应该寻找的东西吗?

我尝试在激活功能中添加console.log输出,但我不知道它在哪里。

1 个答案:

答案 0 :(得分:1)

我今天遇到了这个问题,并试图找出问题所在。它在调试期间有效,但在打包和安装后没有。为了更清楚一点,如果我打包在我的开发盒上,安装将按预期工作,但如果我的CI机器(VSTS)构建它,它就不会。

事实证明,创建的VSIX文件的大小是一个数量级的不同。这是因为VSIX中node_modules的数量变化很大!经过调查,结果发现npm2和npm3之间的差异导致了这个问题。 npm2(今天是VSTS所做的)以不同于npm3的方式打包npm模块(显然它与VS Code不兼容)。