命令

  1. c+s+p

    1. // package.json
    2. {
    3. "main": "./out/extension.js",
    4. "activationEvents": [
    5. "onCommand:vscode-plugin-learn.helloWorld"
    6. ],
    7. "contributes": {
    8. "commands": [
    9. {
    10. "command": "vscode-plugin-learn.helloWorld",
    11. "title": "Hello World"
    12. }
    13. ],
    14. }
    15. }
    1. // extension.js
    2. import vscode from 'vscode';
    3. export function activate(context: vscode.ExtensionContext) {
    4. let disposable = vscode.commands.registerCommand('vscode-plugin-learn.helloWorld', (uri) => {
    5. vscode.window.showInformationMessage(`Hello World uri:${uri}`);
    6. });
    7. context.subscriptions.push(disposable);
    8. }

    image.png

  2. 右键菜单

    1. // package.json
    2. {
    3. "contributes": {
    4. "menus": {
    5. "editor/context": [
    6. {
    7. "when": "editorFocus",
    8. "command": "vscode-plugin-learn.helloWorld",
    9. "group": "navigation"
    10. }
    11. ],
    12. }
    13. }
    14. }

    image.png

  3. 快捷键

    1. {
    2. "contributes": {
    3. "keybindings": [
    4. {
    5. "command": "vscode-plugin-learn.helloWorld",
    6. "key": "ctrl+f11",
    7. "mac": "cmd+f11",
    8. "when": "editorTextFocus"
    9. }
    10. ]
    11. }
    12. }

    image.png

  4. 文件右键

    1. "contributes": {
    2. "menus": {
    3. "explorer/context": [
    4. {
    5. "command": "vscode-plugin-learn.helloWorld",
    6. "group": "navigation"
    7. }
    8. ]
    9. }
    10. },

    image.png

  5. 右上方icon

  1. "contributes": {
  2. "commands": [
  3. {
  4. "command": "vscode-plugin-learn.helloWorld",
  5. "title": "Hello World",
  6. "icon": "./out/images/code.svg"
  7. }
  8. ],
  9. "menus": {
  10. "editor/title": [
  11. {
  12. "when": "editorFocus",
  13. "command": "vscode-plugin-learn.helloWorld",
  14. "group": "navigation"
  15. }
  16. ]
  17. }
  18. },

image.png