'is there some event like onEditorOpen?

what i want to do

i want to write a plugin which could open file(which code could not) use user configed cmd.

user config like

{
    'mp3':'c:/mp3player/mp3.exe {file_path}'
}

when i use code to open a mp3 the plugin will run this cmd

what the problem

i could not fould a event triger me on each file open

what i have know/try

vscode has some event like

  1. workspaceContains:${toplevelfilename}
  2. onLanguage:${language}

but all of this are hardcode in package.json and could not triger on all file type

help me

it there some advise? maybe this is not a vscode plugin should do?
thanks



Solution 1:[1]

The normal approach for that is to listen to the didOpen workspace event:

workspace.onDidOpenTextDocument((doc: TextDocument) => {
    if (doc.languageId == "mp3" && doc.uri.scheme === "file") {
        // do something
    }
});

But note: vscode will not allow to open big or binary files. It will hence not activate your extension for that.

Solution 2:[2]

You can create such an application by using VS Code's Custom Editor API.

It seems that there is already an extension to play audio files. https://marketplace.visualstudio.com/items?itemName=sukumo28.wav-preview

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Lischke
Solution 2 invalid