Is there a way to extend the supported languages/grammars in Visual Studio Code? I'd like to add a custom language syntax, but I've not been able to find any information on how language services are provided.
Can anybody point to any references or even examples of existing language implementations?
Using reverse engineering you can add a new language to VSCode. You can take a look on how typescript is implemented as a JavaScript plugin and how it communicates with node.exe via pipe. But it's a hard thing since it's coming all without documentation I'll provide a really short documentation here:
You can define a new plugin in the plugins folder
C:\Users\USER\AppData\Local\Code\app-0.3.0\resources\app\plugins
.Copy the typescript plugin folder and rename mentioned file extensions and language names in all files to your new language, so that your new plugin is going to be used when a .mylang file is opened.
In
typescriptServiceClient.js
you see that a child process is being forked and that itsstdout
is coupled to anew WireProtocol.Reader
. Bind your ownmylanguage.exe
(you'll probably need to write that exe on your own). VSCode asks that binary to get more language specific information.In
typescriptMain.js
you find the feature registration for the language. Delete every call tomonaco.Modes.XXXXXXSupport.register
exceptmonaco.Modes.DeclarationSupport.register
.Now open a directory in VSCode that contains .mylang files and open one of them via
CTRL+P + FileName
. Right click on an identifier and selectGo to Definition
. VSCode sends now a request like this via StdIn to your exeVSCode expects an answer like this:
If everything works VSCode will open MyOtherFile.mylang and set the cursor to line 124 in column 3.
Try it on your own ;-)