如何让 VS Code 将文件扩展名视为某种语言? [英] How to make VS Code treat a file extensions as a certain language?

查看:31
本文介绍了如何让 VS Code 将文件扩展名视为某种语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

或者有没有办法切换当前文件的语言,以便正确突出显示语法?

Or is there a way to switch the current file's language so that the syntax is highlighted correctly?

例如,*.jsx 实际上是 JavaScript,但 VS Code 无法识别.

For example, *.jsx is actually JavaScript but VS Code doesn't recognize it.

推荐答案

Visual Studio Code 中,您可以将用于语言突出显示的持久文件关联添加到您的 settings.json 文件中,如下所示:

In Visual Studio Code, you can add persistent file associations for language highlighting to your settings.json file like this:

// Place your settings in this file to overwrite the default settings
{
  "some_setting": custom_value,
  ...

  "files.associations": {
    "*.thor": "ruby",
    "*.jsx": "javascript",
    "Jenkinsfile*": "groovy"
  }
}

您可以使用 Ctrl+Shift+P(或 View -> Command Palette 从菜单中),然后键入 settings JSON.选择首选项:打开设置 (JSON) 以打开您的 settings.json.

You can use Ctrl+Shift+P (or View -> Command Palette from the menu) and then type settings JSON. Choose Preferences: Open Settings (JSON) to open your settings.json.

要找到正确的语言 ID,请使用 Ctrl+Shift+P(或 View ->Command Palette(从菜单中选择),然后键入 Change Language Mode.您可以在列表中看到语言 ID,例如键入 docker 以查找 Docker 文件的语言 ID (dockerfile).在上例的第一项中,.thor 是文件结尾,ruby 是语言 ID.

To find the proper language ID, use Ctrl+Shift+P (or View -> Command Palette from the menu) and then type Change Language Mode. You can see the language ID in the list, e.g. type docker to find the language ID for Docker files (dockerfile). In the first entry in the example above, .thor is the file ending, ruby is the language ID.

Files: Associations 功能首次在 Visual Studio Code 1.0 版(2016 年 3 月)中引入.检查发行说明中可用的通配符模式和文档中的 href="https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers" rel="noreferrer">已知语言字符串.

The Files: Associations feature was first introduced in Visual Studio Code version 1.0 (March 2016). Check the available wildcard patterns in the release notes and the known language strings in the documentation.

这篇关于如何让 VS Code 将文件扩展名视为某种语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆