sau*_*rav 6 visual-studio-code vscode-extensions
我通过以下方式生成了一个示例扩展。 https://code.visualstudio.com/api/get-started/your-first-extension
当我从调试视图运行扩展并搜索扩展“Hello World”时。它根本不会出现在命令面板中。
我的包.json
{
"name": "testextension",
"displayName": "TestExtension",
"description": "",
"version": "0.0.1",
"engines": {
"vscode": "^1.76.0"
},
"categories": [
"Other"
],
"activationEvents": [],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "testextension.helloWorld",
"title": "Hello World"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.76.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"eslint": "^8.34.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"typescript": "^4.9.5",
"@vscode/test-electron": "^2.2.3"
}
}
Run Code Online (Sandbox Code Playgroud)
扩展名.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';
// 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) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "testextension" is now active!');
// 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
let disposable = vscode.commands.registerCommand('testextension.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from TestExtension!');
});
context.subscriptions.push(disposable);
}
// This method is called when your extension is deactivated
export function deactivate() {}
Run Code Online (Sandbox Code Playgroud)
小智 8
在扩展中,该engines.vscode属性指定运行扩展所需的 VS Code 本身的最低版本。
包.json
"engines": {
"vscode": "^1.76.0"
}
Run Code Online (Sandbox Code Playgroud)
开发人员设置中没有消息告诉您您自己的版本已过时;扩展程序只是无法加载。
因此请始终使用最新版本的 VC Code 来开发扩展,或者尝试更改 package.json 中所需的版本。
看来使用 yeoman 代码生成器生成的代码与我拥有的 VS 代码版本(1.73)不兼容。
例如,如其他答案中所述,对于 vscode 版本 >= 1.74 不需要明确提及激活事件
我升级了我的 vscode (1.76) 并且它起作用了。
| 归档时间: |
|
| 查看次数: |
1629 次 |
| 最近记录: |