Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

javascript - VSCode extension kick function when just open file

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"
        }
    ]
},
question from:https://stackoverflow.com/questions/65545667/vscode-extension-kick-function-when-just-open-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
"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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...