Alloy in Visual Studio Code

For those in Formal Software Engineering domain, Alloy should be a common name. By itself, it is awesome for preparing and checking a model. However, the editor itself does not support auto complete, even for the symbols written in the same file. Therefore, some people of the community created extensions that support syntax highligting of Alloy syntax in Visual Studio Code and Atom.

One slight problem though. The only way to run the nicely crafted alloy files is to run them through the Alloy program. And we can connect Visual Studio Code and Alloy program quiet easily using another handy extension called Code Runner. All you have to do is to install this extension, and add the mapping for the Alloy languages.

By default, the code runner checks the following settings:

1
2
3
4
5
6
7
8
9
10
11
{"code-runner.executorMap": {
    "javascript": "node",
    "php": "C:\\php\\php.exe",
    "python": "python",
    "perl": "perl",
    "ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
    "go": "go run",
    "html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
    "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
    "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}}

As you can see, this maps javascript, php, python and some more by default using these configuration. To add this, we only need to append the following line:

1
2
3
{
"alloy": "java -jar <pathToAlloyHere> $fullfilename"
}

And that’s it! Now if you invoke the code runner (generally using ctrl+enter), it will automatically run Alloy using the file you are using.

Written on February 12, 2018