Contribute language association from extensions in VSCode

╄→尐↘猪︶ㄣ 提交于 2020-01-17 00:37:30

问题


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.


回答1:


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.




回答2:


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"
        ],
      }
    ]
}


来源:https://stackoverflow.com/questions/55677168/how-can-i-write-a-vsc-snippets-extension-for-a-language-that-is-not-listed-on-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!