0

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

找不到命令的处理程序:'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在激活函数中添加输出,但我也不知道它在哪里。

4

1 回答 1

1

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

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

于 2016-01-19T18:47:12.697 回答