Ceci est une ancienne révision du document !
Table des matières
Prérequis
La documentation est Extension API de Visual Studio Code. Archive du 11/12/2020 le 01/02/2021
Node.js
Il faut installer Node.js qui possède une application pour créer un squelette de module.
Installer les programmes yo
et generator-code
par :
npm install -g yo generator-code
Création du module
Générer le module de base pour la coloration syntaxique :
yo code
Résultat de la console :
? ========================================================================== We're constantly looking for ways to make yo better! May we anonymously report usage statistics to improve the tool over time? More info: https://github.com/yeoman/insight & http://yeoman.io ========================================================================== Yes _-----_ ╭──────────────────────────╮ | | │ Welcome to the Visual │ |--(o)--| │ Studio Code Extension │ `---------´ │ generator! │ ( _´U`_ ) ╰──────────────────────────╯ /___A___\ / | ~ | __'.___.'__ ´ ` |° ´ Y ` ? What type of extension do you want to create? New Language Support Enter the URL (http, https) or the file path of the tmLanguage grammar or press ENTER to start with a new grammar. ? URL or file to import, or none for new: ? What's the name of your extension? CELLman Lang ? What's the identifier of your extension? cellman-lang ? What's the description of your extension? Syntax highlighting for CELLman lang Enter the id of the language. The id is an identifier and is single, lower-case name such as 'php', 'javascript' ? Language id: cellman Enter the name of the language. The name will be shown in the VS Code editor mode selector. ? Language name: CELLman Enter the file extensions of the language. Use commas to separate multiple entries (e.g. .ruby, .rb) ? File extensions: .cmc, .TRAN Enter the root scope name of the grammar (e.g. source.ruby) ? Scope names: source.cmc ? Initialize a git repository? Yes create cellman-lang\syntaxes\cellman.tmLanguage.json create cellman-lang\.vscode\launch.json create cellman-lang\package.json create cellman-lang\README.md create cellman-lang\CHANGELOG.md create cellman-lang\vsc-extension-quickstart.md create cellman-lang\language-configuration.json create cellman-lang\.vscodeignore create cellman-lang\.gitignore create cellman-lang\.gitattributes Your extension cellman-lang has been created! To start editing with Visual Studio Code, use the following commands: cd cellman-lang code . Open vsc-extension-quickstart.md inside the new extension for further instructions on how to modify, test and publish your extension. For more information, also visit http://code.visualstudio.com and follow us @code.
Syntaxe des fichiers
package.json
- languages
Dans ce fichier, il faut uniquement modifier la partie contributes
(documentation Extension points).
{ "contributes": { "languages": [{ "id": "cellman_cmc", "aliases": ["CELLman", "cellman"], "extensions": [".cmc", ".TRAN"], "configuration": "./language-configuration.json", "filenames": [], "firstLine": "..." }], "grammars": ... } }
Dans languages
, on définit un tableau de langages identifié par un id
.
Le premier alias servira de label.
Les extensions
filtreront les fichiers où s'appliquera la coloration syntaxique. Chaque extension unique ne doit être que dans un seul langage. Si une extension est présente dans deux langages, l'un des deux sera simplement ignoré.
Avec filenames
, c'est un filtre qui prend en compte le nom du fichier et pas uniquement son extension. C'est utile pour les fichiers sans extension.
Avec firstLine
, on applique une expression régulière sur le contenu de la première ligne du fichier.