A comprehensive Language Server Protocol extension for VS Code that provides IntelliSense, syntax highlighting, code completion, and debugging support for NWScript - the scripting language used in Star Wars: Knights of the Old Republic (KOTOR) and KOTOR II: The Sith Lords (TSL).
- Syntax Highlighting - Full NWScript syntax highlighting with KOTOR-specific patterns
- IntelliSense - Auto-completion for functions, constants, variables, and keywords
- Error Detection - Real-time syntax validation and semantic analysis
- Hover Information - Detailed documentation on hover for functions and constants
- Go to Definition - Navigate to function and variable declarations
- Document Symbols - Outline view of functions, variables, and structures
- Signature Help - Parameter hints for function calls
- Game Version Detection - Automatically detects target game version (KOTOR 1 vs KOTOR 2)
- Version-Specific Validation - Shows only functions/constants available in the target game
- KOTOR Function Library - Complete database of KOTOR 1 and KOTOR 2 functions and constants
- Include File Support - Resolves
#includedirectives with bundled KOTOR script libraries - Hungarian Notation - Supports KOTOR's variable naming conventions (nValue, fDistance, etc.)
- NWScript Debugger - Debug NWScript files directly in VS Code
- Breakpoints - Set breakpoints and step through code execution
- Variable Inspection - Examine variable values during debugging
- Call Stack - View the execution call stack
- Semantic Analysis - Deep code analysis with type checking
- Variable Value Inference - Hover to see inferred variable values
- Expression Evaluation - Evaluate complex expressions at compile-time
- Include Dependency Tracking - Tracks include file dependencies and circular references
- Quick Fixes - Automated fixes for common issues (e.g., missing game version)
Open VS CodeGo to Extensions (Ctrl+Shift+X)Search for "HoloLSP"Click Install
- Download the
.vsixfile from the Releases page - Open VS Code
- Run
Extensions: Install from VSIX...from the Command Palette (Ctrl+Shift+P) - Select the downloaded
.vsixfile
-
Create a new NWScript file with the
.nssextension -
Specify the target game version at the top of your file:
// @target kotor1 // or // @target kotor2
HoloLSP supports targeting specific KOTOR game versions for accurate validation. Add one of these comments within the first 10 lines of your script:
// @target kotor1 // KOTOR 1
// @target kotor2 // KOTOR 2/TSL
// @game kotor1 // Alternative syntax
// @version k1 // Short form
// #pragma target kotor1 // Pragma style
/** @target kotor1 */ // JSDoc style
// kotor1 only // Simple commentkotor1,k1- Knights of the Old Republic (2003)kotor2,tsl,k2- Knights of the Old Republic II: The Sith Lords (2004)
// @target kotor1
// Example KOTOR 1 script with full language support
#include "k_inc_generic"
void main() {
object oPC = GetFirstPC();
// KOTOR-specific functionality
int nStackSize = GetModuleItemAcquiredStackSize();
object oItem = GetModuleItemAcquired();
// Global variable management
SetGlobalNumber("K_CURRENT_PLANET", PLANET_TARIS);
int nPlanet = GetGlobalNumber("K_CURRENT_PLANET");
// Vector operations
vector vPosition = GetPosition(oPC);
vector vNewPos = vPosition + Vector(0.0, 0.0, 1.0);
// Control flow with KOTOR constants
if (GetIsPC(oPC)) {
switch (nPlanet) {
case PLANET_TARIS:
PrintString("On Taris");
break;
case PLANET_DANTOOINE:
PrintString("On Dantooine");
break;
default:
PrintString("Unknown planet");
break;
}
}
}Configure HoloLSP through VS Code settings:
{
"holoLSP.maxNumberOfProblems": 100,
"holoLSP.builtinScriptsDirectory": "/path/to/kotor/scripts"
}-
holoLSP.maxNumberOfProblems(number, default: 100)
Controls the maximum number of problems produced by the server. Configure this if it does not run well on your system. -
holoLSP.builtinScriptsDirectory(string, optional)
Directory path for builtin KOTOR scripts. When set, "Go to Definition" for included scripts will resolve to files in this directory instead of using the virtualhololsp://scheme. Supports absolute paths, relative paths (relative to the current file), orfile://URIs. This setting is particularly useful for non-VS Code LSP clients like Emacs that cannot handle custom URI schemes.
.nss- NWScript source files.ncs- Compiled NWScript files (read-only support, mostly WIP)
HoloLSP includes comprehensive function and constant definitions for both KOTOR games:
- 5000+ Functions - Complete KOTOR 1 and KOTOR 2 function libraries (from e.g. nwscript.nss)
- 2000+ Constants - All game constants, categorized for organizational usage.
- Include Files - Bundled KOTOR script library includes (
k_inc_generic,k_inc_utility, etc.) - Type Definitions - Complete type system with proper validation
HoloLSP can infer and display variable values:
int a = 10;
int b = 5;
int c = (a > b) ? 100 : 200; // Hover shows: c = 100Automatically resolves include files from the bundled KOTOR libraries:
#include "k_inc_generic" // Resolves to bundled library
#include "some_local_script" // Looks for local file (should be adjacent to the script in question--modules aren't supported yetEvaluates complex expressions in real time:
const int RESULT = 2 + 3 * 4; // Shows: RESULT = 14
vector vPos = [1.0, 2.0, 3.0] + Vector(1.0, 0.0, 0.0); // Shows computed resultFor editors like Emacs that work with the LSP but don't handle custom URI schemes:
{
"holoLSP.builtinScriptsDirectory": "/tmp/nss",
"holoLSP.maxNumberOfProblems": 1000
}This will make "Go to Definition" return file:///tmp/nss/k_inc_generic.nss instead of hololsp:/kotor/k_inc_generic.nss.
- Fixed "Go to Definition": Now supports configurable URI schemes for better compatibility with non-VS Code editors
- Improved "Find All References": Now excludes commented-out code from reference results
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Add tests for new features (preferably using Jest)
- Update documentation for user-facing changes
- Fork the repo, submit a PR.
- Large include files may cause performance issues during initial parsing (e.g.,
nwscript.nss, or large include chains) - Some complex macro expansions are not fully supported
- Most of the assumptions about the syntax were heavily based on C/C++, others taken from projects like GitHub's own markdown template for nwn:ee. Please report any incorrect syntax that isn't valid in the games.
- Enhanced Debugging - More advanced debugging features
- Script Compilation - Built-in NWScript compiler
- Module Integration - Direct integration with KOTOR module files (ERF/RIM/MOD) potentially even BIK.
- Template Support - Script templates and snippets for common KOTOR patterns
- Performance Optimization - Faster parsing for large projects
Most of this section is untested.
- Set breakpoints by clicking in the gutter next to line numbers
- Start debugging using F5 or the "Debug NWScript" command
- Step through code using the debugging controls
- Inspect variables in the Variables panel
- Node.js (v16 or higher)
- npm or yarn
- VS Code (v1.75.0 or higher)
-
Clone the repository:
git clone https://github.com/th3w1zard1/HoloLSP.git cd HoloLSP -
Install dependencies:
npm install
-
Compile the project:
npm run compile
-
Watch for changes during development:
npm run watch
HoloLSP/
├── client/ # VS Code extension client
│ ├── src/
│ │ ├── extension.ts # Main extension entry point
│ │ ├── debugAdapter.ts # Debug adapter implementation
│ │ └── testing.ts # Test framework integration
│ └── package.json
├── server/ # Language server implementation
│ ├── src/
│ │ ├── server.ts # Main language server
│ │ ├── nwscript-parser.ts # NWScript parser
│ │ ├── nwscript-lexer.ts # NWScript lexer
│ │ ├── completion-provider.ts # Code completion
│ │ ├── diagnostic-provider.ts # Error diagnostics
│ │ ├── kotor-definitions.ts # KOTOR function/constant definitions
│ │ ├── game-version-detector.ts # Game version detection
│ │ └── semantic-analyzer.ts # Semantic analysis
│ └── package.json
├── mcp/ # Model Context Protocol integration
├── syntaxes/ # TextMate grammar for syntax highlighting
├── examples/ # Example NWScript files
├── vendor/ # Third-party dependencies (PyKotor)
└── package.json # Main package configuration# Run server tests
npm run build:tests
cd server && npm test
# Run with watch mode
cd server && npm run test:watch- Open the project in VS Code
- Press F5 to launch a new Extension Development Host
- Use "Client + Server" configuration to debug both client and server simultaneously
This project is licensed under the MIT License - see the LICENSE file for details.
- PyKotor Team - For the comprehensive KOTOR script definitions and tools
- KOTOR Modding Community - For extensive testing and feedback
- BioWare - For creating the amazing KOTOR games and NWScript language
- GitHub Issues - Report bugs and request features
- Discussions - Community support and questions
May the Force be with your scripts! ⚡