参考: https://code.visualstudio.com/api/references/contribution-points
package.json
"contributes": {
"commands": [
{
"command": "extension.hello",
"title": "hello"
}
]
}
extension.ts
commands.registerCommand('extension.hello', () => {
window.showInformationMessage('Hello World!');
});
package.json
"contributes": {
"configuration": {
"title": "TypeScript configuration",
"properties": {
"typescript.useCodeSnippetsOnMethodSuggest": {
"type": "boolean",
"default": false,
"description": "Complete functions with their parameter signature."
},
"typescript.tsdk": {
"type": ["string", "null"],
"default": null,
"description": "Specifies the folder path containing the tsserver and lib*.d.ts files to use."
}
}
}
}
文件 - 首选项 - 设置
输入框输入TypeScript configuration
读取配置
extension.ts
const config = vscode.workspace.getConfiguration('typescript');
console.log(config.get('useCodeSnippetsOnMethodSuggest')); // false
package.json
"contributes": {
"commands": [
{
"command": "extension.menu_title",
"title": "showSource",
"icon": {
"light": "./media/love_light.svg",
"dark": "./media/love_dark.svg"
}
}
],
"menus": {
"editor/title": [{
"command": "extension.menu_title",
"group": "navigation"
}]
}
},
extension.ts
export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("extension.menu_title", () => {
vscode.window.showInformationMessage('点击了爱心');
});
}
"menus": {
"commandPalette": [{
"command": "extension.menu_title",
}]
"commands": [
{
"command": "extension.menu_title",
"title": "showSource"
}
],
package.json
"menus": {
"explorer/context": [{
"command": "extension.menu_title"
}]
}
package.json
"menus": {
"editor/context": [{
"command": "extension.menu_title"
}]
}
"viewsContainers": {
"activitybar": [
{
"id": "package-explorer",
"title": "Package Explorer",
"icon": "./media/dep.svg"
}
]
},
"views": {
"package-explorer": [
{
"id": "nodeDependencies",
"name": "Node Dependencies"
}
]
},
"menus": {
"view/title": [{
"command": "view.menu_title",
"group": "navigation"
}],
"view/item/context": [
{
"command": "view.menu_title",
"group": "navigation"
}
]
}
"commands": [
{
"command": "view.menu_title",
"title": "showSource",
"icon": {
"light": "./media/love_light.svg",
"dark": "./media/love_dark.svg"
}
}
]
extension.ts
export function activate(context: vscode.ExtensionContext) {
const nodeDependenciesProvider = new DepNodeProvider(vscode.workspace.rootPath || '');
vscode.window.registerTreeDataProvider('nodeDependencies', nodeDependenciesProvider);
vscode.commands.registerCommand("view.menu_title", () => {
vscode.window.showInformationMessage('点击了爱心');
});
}
参考: https://code.visualstudio.com/api/extension-guides/tree-view
view/item/context
参考: https://code.visualstudio.com/api/extension-guides/tree-view
touchBar
comments/commentThread/context
comments/comment/title
comments/comment/context
package.json
"activationEvents": [
"*"
],
extension.ts
export function activate(context: vscode.ExtensionContext) {
console.log('插件激活');
}
package.json
"activationEvents": [
"onCommand:extension.hello"
],
extension.ts
export function activate(context: vscode.ExtensionContext) {
console.log('插件激活');
vscode.commands.registerCommand("extension.hello", () => {
vscode.window.showInformationMessage('Hello World');
});
});
}