语言标识符
在 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(), '.', '$');
新标识符指南
定义新语言标识符时,请遵循以下指南:
- 使用小写的编程语言名称。
- 在市场中搜索其他扩展,以查看是否已经使用了语言标识符。
已知的语言标识符
下表列出了已知的语言标识符:
Language | Identifier |
---|---|
ABAP | abap |
Windows Bat | bat |
BibTeX | bibtex |
Clojure | clojure |
Coffeescript | coffeescript |
C | c |
C++ | cpp |
C# | csharp |
Compose | dockercompose |
CSS | css |
CUDA C++ | cuda-cpp |
D | d |
Dart | dart |
Delphi | pascal |
Diff | diff |
Dockerfile | dockerfile |
Erlang | erlang |
F# | fsharp |
Git | git-commit and git-rebase |
Go | go |
Groovy | groovy |
Handlebars | handlebars |
Haml | haml |
Haskell | haskell |
HTML | html |
Ini | ini |
Java | java |
JavaScript | javascript |
JavaScript JSX | javascriptreact |
JSON | json |
JSON with Comments | jsonc |
Julia | julia |
LaTeX | latex |
Less | less |
Lua | lua |
Makefile | makefile |
Markdown | markdown |
Objective-C | objective-c |
Objective-C++ | objective-cpp |
OCaml | ocaml |
Pascal | pascal |
Perl | perl and perl6 |
PHP | php |
Plain Text | plaintext |
PowerShell | powershell |
Pug | jade , pug |
Python | python |
R | r |
Razor (cshtml) | razor |
Ruby | ruby |
Rust | rust |
SCSS | scss (syntax using curly brackets), sass (indented syntax) |
ShaderLab | shaderlab |
Shell Script (Bash) | shellscript |
Slim | slim |
SQL | sql |
Stylus | stylus |
Svelte | svelte |
Swift | swift |
TypeScript | typescript |
TypeScript JSX | typescriptreact |
TeX | tex |
Visual Basic | vb |
Vue | vue |
Vue HTML | vue-html |
XML | xml |
XSL | xsl |
YAML | yaml |