Mod:Creation Kit/Visual Studio Code

Visual Studio Code is a source code editor developed by Microsoft. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. It is also customizable, so users can change the editor's theme, keyboard shortcuts, and preferences. It is free and open-source, although the official download is under a proprietary license.

Visual Studio Code is based on Electron, a framework which is used to deploy Node.js applications for the desktop running on the Blink layout engine. Although it uses the Electron framework, the software does not use Atom and instead employs the same editor component (codenamed "Monaco") used in Visual Studio Team Services (formerly called Visual Studio Online).

Install Visual Studio Code
Go to the Visual Studio Code website, download the setup file, and run it.

Install packages

 * Papyrus (syntax highlighting)
 * Papyrus Compiler (run the Papyrus compiler from the command menu)

Usage
After installing VS Code, install the Papyrus packages by browsing to the package's extension page and click install or the VS Code's extension installer (CTRL+SHIFT+X)

If your project is using project files (.ppj) you may want to associate .ppj files as XML Go to File > Settings and add the following to *user settings*:

"files.associations": { "*.ppj": "xml" }

User settings should look something like this:

{   ...    "editor.fontSize": 13, "files.associations": { "*.ppj": "xml" }

... }

Compilation
If you want to compile your Papyrus scripts from within Visual Studio Code you can use the Papyrus Compiler package (see packages section). The package contributes commands to VSC for running the Papyrus compiler. See the package homepage for setup.

Alternatively you can utilize VS Code's build and tasks system.

Using the build and tasks system
Note: Replace occurences of  with the path to the directory where your game is installed (Eg.: C:\Program Files (x86)\Steam\steamapps\common\Fallout 4)

Compile single file using default build task

 * 1) First add the ScriptCompileDevVS.bat to your \Data\Scripts\Source\User directory. The bat file contains basic compiler configuration for development.
 * 2) If not exists create a directory named '.vscode' (without quotes) in your \Data\Scripts\Source\User directory.
 * 3) Add the file tasks.json in the new .vscode directory.
 * 4) In tasks.json make sure the directory paths in the windows.command property are correct.
 * 5) Save tasks.json

Now, you may test to see if everything is working as expected by opening one of your .tsc files. Press CTRL+SHIFT+B (Run Build Task) to compile. The built-in terminal should automatically open and output the results. If everything has been configured correctly you should see the compilation success message.

Compile file on CTRL+S
If you want to compile the edited file every time you save the file (CTRL+S) you can add a hook in keybindings.json


 * 1) Choose File > Preferences > Keyboard Shortcuts
 * 2) Click the keybindings.json link at the top of the screen (below the search input)
 * 3) In your keybindings.json add the following JSON object to the JSON array (between the brackets)

{       "key": "ctrl+s", "command": "workbench.action.tasks.build", "when": "editorLangId == papyrus" }

This will run the build task for the currently edited Papyrus file each time you save the file using the CTRL+S shortcut. Please note that the task will not run if save is triggered from elsewhere in VS Code (eg. Menu - File > Save)

Read more about keybindings here: https://code.visualstudio.com/docs/getstarted/keybindings

Files
ScriptCompileDevVS.bat

set compilerPath=%2 set gameDirectory=%~3

%compilerPath% %1 -f="%gameDirectory%\Data\Scripts\Source\Base\Institute_Papyrus_Flags.flg" -i="%gameDirectory%\Data\Scripts\Source\User;%gameDirectory%\Data\Scripts\Source\Base" -o="%gameDirectory%\Data\Scripts"

.vscode/tasks.json

{   // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ {           "label": "Compile Papyrus Script (development)", "type": "shell", "windows": { "command": ".\\ScriptCompileDevVS.bat '${file}' 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Fallout 4\\Papyrus Compiler\\PapyrusCompiler.exe' 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Fallout 4'", },           "presentation": { "reveal": "always" },           "group": { "kind": "build", "isDefault": true }       }    ] }