Contribute language association from extensions in

2020-04-21 07:40发布

How can I contribute a language association from an extension in VSCode?

In settings.json it would've looked like this:

"files.associations": {
    "*.something": "markdown"
}

I know that it's possible to use vscode.languages.setTextDocumentLanguage. But that seems excessive to do every time the activeEditor changes, and it's one more event listener.

Using the API to write into user settings doesn't seem right either.

2条回答
成全新的幸福
2楼-- · 2020-04-21 08:03

Yes, extensions can contribute settings via configurationDefaults. However, I don't think this works for the files.associations setting.

What you can do instead is contribute a new file extension for the markdown language:

"contributes": {
    "languages": [
        {
            "id": "markdown",
            "extensions": [
                "something"
            ]
        }
    ]
}

This won't replace the previous registration of the markdown language, instead it will be merged with it.

查看更多
ら.Afraid
3楼-- · 2020-04-21 08:28

Make the following change to your package.json, I figured it out by studying an existing extension.

You must add . before something

Also see : How can I write a vsc snippets extension for a language that is not listed on visual studio code

"contributes": {
    "languages": [
      {
        "id": "markdown",
        "extensions": [
          ".something"
        ],
      }
    ]
}
查看更多
登录 后发表回答