语言标识符

在 Visual Studio Code 中,每种语言模式都有一个唯一的特定语言标识符。除了在设置中(例如将文件扩展名关联到某种语言时),用户很少见到该标识符。

    "files.associations": {
        "*.myphp": "php"
    }

请注意,精确匹配标识符时区分大小写('Markdown' != 'markdown')

对于 VS Code 扩展开发者而言,在添加新语言功能或替换语言支持时,语言标识符至关重要。

每种语言通过扩展的 package.json 文件中的 languages 配置点来定义其 id

    "languages": [{
        "id": "java",
        "extensions": [ ".java", ".jav" ],
        "aliases": [ "Java", "java" ]
    }]

语言支持是使用语言标识符添加的

    "grammars": [{
        "language": "groovy",
        "scopeName": "source.groovy",
        "path": "./syntaxes/Groovy.tmLanguage.json"
    }],
    "snippets": [{
        "language": "groovy",
        "path": "./snippets/groovy.json"
    }]
languages.registerCompletionItemProvider('php', new PHPCompletionItemProvider(), '.', '$');

新标识符指南

在定义新的语言标识符时,请遵循以下准则

  • 使用小写的编程语言名称。
  • 在插件市场(Marketplace)中搜索其他扩展,查看该语言标识符是否已被使用。

已知语言标识符

下表列出了已知的语言标识符

语言 标识符
代理 chatagent
Batch bat
BibTeX bibtex
Binary code-text-binary
C c
C# csharp
C++ cpp
Clojure clojure
Code Snippets snippets
CoffeeScript coffeescript
Compose dockercompose
CSS css
CUDA C++ cuda-cpp
Dart dart
Diff diff
Docker dockerfile
Dotenv dotenv
F# fsharp
Git Commit Message git-commit
Git Rebase Message git-rebase
Go go
Groovy groovy
Handlebars handlebars
HLSL hlsl
HTML html
Ignore ignore
Ini ini
说明 instructions
Java java
JavaScript javascript
JavaScript JSX javascriptreact
JSON json
JSON Lines jsonl
JSON with Comments jsonc
Julia julia
Julia Markdown juliamarkdown
LaTeX latex
Less less
Log log
Lua lua
Makefile makefile
Markdown Markdown
MS SQL sql
Objective-C objective-c
Objective-C++ objective-cpp
Perl perl
PHP php
Plain Text plaintext
PowerShell powershell
Prompt prompt
属性 properties
Pug jade
Python python
R r
Raku raku
Razor razor
reStructuredText restructuredtext
Ruby ruby
Rust rust
SCSS scss
Search Result search-result
ShaderLab shaderlab
Shell Script shellscript
Skill skill
Swift swift
TeX tex
TypeScript typescript
TypeScript JSX typescriptreact
Visual Basic vb
WebAssembly Text Format wat
XML xml
XSL xsl
YAML yaml
© . This site is unofficial and not affiliated with Microsoft.