NWScript: EE Language Server is a Visual Studio Code extension for the NWScript language.
Neverwinter Nights home and installation folders.
Simply open a project with nss files and the extension installed.
{
"editor.formatOnSave": true,
"files.associations": {
"*.nss": "nwscript"
},
"[nwscript]": {
"editor.defaultFormatter": "PhilippeChab.nwscript-ee-language-server"
},
"nwscript-ee-lsp.formatter": {
"enabled": true,
"executable": "clang-format",
"ignoredGlobs": ["/folder/to/ignore/*.nss", "file/to/ignore/filename.nss"],
"style": {
"BasedOnStyle": "Google",
"AlignTrailingComments": true,
"AlignConsecutiveAssignments": true,
"ColumnLimit": 250,
"BreakBeforeBraces": "Allman",
"AlignEscapedNewlinesLeft": true,
"AlwaysBreakBeforeMultilineStrings": true,
"MaxEmptyLinesToKeep": 1,
"TabWidth": 4,
"IndentWidth": 4,
"UseTab": "Always"
}
}
}
Notes:
{
"nwscript-ee-lsp.compiler": {
"enabled": true,
"verbose": false,
"nwnHome": "C:\\Users\\YOUR_USERNAME\\Documents\\Neverwinter Nights",
"nwnInstallation": "D:\\Program Files (x86)\\Steam\\steamapps\\common\\Neverwinter Nights"
}
}
Notes:
verbose
setting to true
if you wish to see detailed logs of the compilation process.I personally use the One Dark Pro theme . See VS Code documentation if you wish to customize the highlighting further.
npm install -g yarn @vscode/vsce
which will install Yarn, a dependency manager, and vsce, a VS Code packaging library.yarn install
which will install all dependencies using Yarn.vsce package
which will produce a .vsix file.Install From VSIX
and navigate to the package you just produced.Replace /server/scripts/nwscript.nss
by its new version, /server/scripts/base_scripts/
files by their new versions, /server/scripts/ovr/
includes by their new versions and execute yarn run generate-lib-defs
in the server root directory.
The language server symbols or tokens are not generated using an AST like language servers usually do. The NWScript Language Server exploits its TextMate grammar, which is derived from C's, to transform a file of code into tokens. While it works well for most cases since it is a simple scripting language built on C - even for a language like NWScript, we need to cheat and use lookahead and lookbehind strategies to ensure we are in the right context -, it will also fail for complex or uncommon code structures and styles. A TextMate grammar will never cover the most extreme cases of a language grammar. An AST represents the hierarchical structure of a file of code in a much more complete and precise way.
Implementing a language lexer and parser to build its AST is a lot of work, and none was available at the time I implemented this project. Now that NWScript compiler has been made public, it would be much easier to create a utility responsible for parsing a file of code and generating its AST. Implementing this utility and refactoring the whole tokenization engine of the Language Server is, however, a non-negligible amount of work. Considering the fact that the current solution works well for common use, I do not intend to do it.
The nwnsc process doesn't terminate on linux. This is caused by the compiler itself, not the extension.
Please report any issues on the github repository.