【问题标题】:VSCode extension kick function when just open file刚刚打开文件时的VSCode扩展踢功能
【发布时间】:2021-04-09 05:48:30
【问题描述】:

我想打开pubspec.yaml 文件并启动一些功能 VSCode 扩展。 但什么也没发生。 为什么我不能?

"activationEvents": [
    "onLanguage:yml"
],
"main": "./dist/extension.js",
"contributes": {
    "views": {
        "explorer": [
          {
            "id": "mrgao_luckys",
            "name": "pubspec.yaml"
          }
        ]
    },
    "commands": [
        {
            "command": "flutter-pub-version-checker.helloWorld",
            "title": "Hello World"
        }
    ]
},

【问题讨论】:

    标签: javascript typescript visual-studio-code vscode-extensions


    【解决方案1】:
    "activationEvents": [
        "onLanguage:yml"
    ],
    

    此激活事件已发出,感兴趣的扩展将是 每当解析为某种语言的文件被激活时 打开。 [来自onLanguageapi]

    所以当你打开一个yml 文件时,extension 被激活,而不是任何特定的命令。 package.json 的其余部分与此 onLanguage:yml 激活无关。

    如果你只是在你的extension.js 中有这个,你可以看到这个:

    async function activate(context) {
    
      someFunction();   // this function will be run whenever you switch to a `yml` file.
    
      // this will be run too, but it just registers the command, does not trigger it
      // the command is triggered in other ways
      vscode.commands.registerCommand('flutter-pub-version-checker.helloWorld'.....{} )
    }
    

    您的命令flutter-pub-version-checker.helloWorld 没有被语言开关激活 - 它是通过命令面板或键绑定或菜单项选择激活的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-04
      • 2023-03-06
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 2022-10-14
      相关资源
      最近更新 更多