Language syntax, snippets, formatter and build system for Nullsoft Scriptable Install System (NSIS), with language intelligence provided by nsis-lsp.
Screenshot of NSIS in Visual Studio Code with Hopscotch theme
- Language intelligence, provided by the server:
- code actions
- completions
- document symbols
- find references
- go-to-definition
- on-hover information
- rename symbol
- signature help
- Language syntax for NSIS and NSIS Language Files
- Snippets for core NSIS commands, variables and predefines
- Snippets for core plug-ins
- Snippets for core libraries (“Useful Headers”)
- NSIS Diagnostics
- Drunken NSIS
- Formatting
- Build Tools
- Environment Variables
- Converting between NSIS language files and JSON, using NSIS: Convert Language File
You can further extend NSIS support with snippets for third-party plug-ins.
Launch Quick Open, paste the following command, and press Enter
ext install idleberg.nsis
With shell commands installed, you can use the following command to install the extension:
$ code --install-extension idleberg.nsis
Alternatively, you can download the packaged extension from the
Open VSX Registry or install it using the
ovsx command-line tool:
$ ovsx get idleberg.nsisReleased packages bundle the language server for your platform, so there is
nothing else to install. On platforms without a prebuilt binary, install the
server yourself and the extension will find it on your PATH:
$ cargo install nsis-lspWith most commands, you can specify available options before completion. For
instance, rather than completing RequestExecutionLevel and then specifying an
option, you can directly choose RequestExecutionLevel user from the completion
menu.
To complete
compile time commands,
variables or
predefines,
make sure to omit special characters like !, $ and brackets:
includecompletes to!includeINSTDIRcompletes to$INSTDIRNSIS_VERSIONcompletes to${NSIS_VERSION}
However, you have to type __LINE__ to complete to ${__LINE__}.
There are several special cases for your convenience:
MB_OKcompletes toMessageBox MB_OK "messagebox_text"onInitcompletes to aFunction .onInitblockLogicLibcompletes to!include "LogicLib.nsh"
Fuzzy syntax completions that try to iron out some of the inconsistencies in the NSIS language, for instance word order. The name is taken from the Sublime Text package of the same name.
Examples:
Interchangable word order of NSIS language and library functions
ReadFilecompletes toFileReadINIStrReadcompletes toReadINIStrSetSectionTextcompletes toSectionSetTextSetLogcompletes toLogSetFirstFindcompletes toFindFirst${LineFind}completes to${FindLine}
Scripts are formatted by the language server. To do so, run Format Document or adjust your settings for auto-formatting.
Example
{
"editor.formatOnSave": true,
"[nsis]": {
"editor.defaultFormatter": "idleberg.nsis"
},
}The formatter is tweaked through the nsis.formatter.* settings —
commentStyle, endOfLine, printWidth, singleQuote and trimEmptyLines.
Indentation is not among them, since the formatter uses the editor's tabSize
and insertSpaces.
Before you can build, make sure makensis is in your PATH
environment variable. Alternatively, you
can specify the path to makensis in your
user settings.
Example:
{
"nsis.makensis.path": "C:\\Program Files (x86)\\NSIS\\makensis.exe"
}To trigger a build, select NSIS: Save & Compile” from the command-palette or use the default keyboard shortcut Ctrl+Shift+B. The strict option treats warnings as errors and can be triggered using Ctrl+Alt+Shift+B.
On macOS and Linux, makensis can be run through Wine by enabling
nsis.wine.runWithWine. The setting is ignored on Windows.
Note
Wine only applies to compiling. The language server runs makensis directly,
so diagnostics are unavailable on a Wine-only setup.
You can tweak your default settings by editing your user settings.
If you prefer Visual Studio Code's built-in Task Runner to build scripts, you
can create tasks.json in the project root using the NSIS: Create Build Task
command from the
command-palette.
Note
The created Task Runner will adapt to the
user settings
specified in settings.json.
makensis reads NSISDIR and NSISCONFDIR from the environment. Both are
picked up from your system-wide environment variables, and either can be
overridden per platform through the terminal.integrated.env.* setting, so a
workspace that already sets them for its terminal does not have to set them a
second time.
Example
{
"terminal.integrated.env.windows": {
"NSISDIR": "C:\\Program Files (x86)\\NSIS"
}
}Note
Some operating systems require Visual Studio Code to be launched from terminal in order to access system-wide environment variables.
Additionally, you can pass special environment variables prefixed with
NSIS_APP_ to your installer script. They will be treated like normal
definitions and will be stringified at compile-time.
Example
$ export NSIS_APP_ENVIRONMENT=development# installer.nsi
!if ${NSIS_APP_ENVIRONMENT} == "development"
DetailPrint "Valuable Debug Information"
!endifNote
Unlike NSISDIR and NSISCONFDIR, these are read from the environment Visual
Studio Code itself was launched with. Setting them in
terminal.integrated.env.* has no effect.
This extension defaults to UTF-8 with BOM (utf8bom) for NSIS files. If you are working with older scripts, you can override the encoding in your workspace settings:
Example
Per workspace: Add "files.encoding": "windows1252" to the [nsis] section in your .vscode/settings.json Per file: Click the encoding label in the status bar and choose Save with Encoding
Files in this repository fall under the Apache 2.0 License.
{ "[nsis]": { "files.encoding": "windows1252" } }