Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...