VSCode extension kick function when just open file

Viewed 206

I want to open pubspec.yaml file and kick some function VSCode extenision. but nothing happned. Why can't I?

"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"
        }
    ]
},
1 Answers
"activationEvents": [
    "onLanguage:yml"
],

This activation event is emitted and interested extensions will be activated whenever a file that resolves to a certain language gets opened. [from onLanguage api]

So when you open a yml file the extension is activated, not any particular command. The rest of your package.json really has nothing to do with this onLanguage:yml activation.

You can see this if you simply have this in your 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'.....{} )
}

Your command flutter-pub-version-checker.helloWorld is not activated by the language switch - it is activated through the command palette or a keybinding or a menu item selection.

Related