Neutron Language Server Protocol (LSP)¶
The Neutron LSP provides intelligent language features for .nt, .ntsc, and .quark files in your editor.
Features¶
π¨ Syntax Highlighting¶
- Full syntax highlighting for Neutron code (
.nt,.ntsc) - Separate syntax highlighting for Quark config files (
.quark) - Keywords, strings, numbers, comments, and operators are colorized
π§ Autocomplete¶
- Keywords:
fn,let,const,if,else,while,for,return,class,use,safe, etc. - Built-in Functions:
print,println,input,len,type,str,int,float,range,typeof, etc. - Modules: Context-aware module completions (only available after
useimport) use "math"β enablesmath.completionsuse "sys"β enablessys.completionsuse "http"β enableshttp.completions- And more:
json,fmt,time,regex,process,async,websocket
π Hover Documentation¶
- Hover over keywords to see descriptions
- Hover over built-in functions to see signatures and documentation
- Safe mode indicators for
.ntscfiles
βΆοΈ CodeLens¶
- Run button at the top of
.ntand.ntscfiles to execute scripts - Format button to format the current file
π Document Formatting¶
- Format your code with proper indentation
- Accessible via CodeLens "Format" button or editor format command
β Safe Mode Validation¶
.ntscfiles enforce type-safe Neutronsafe { }blocks in.ntfiles are validated- Missing type annotations are flagged as errors
Installation¶
VS Code Extension¶
-
Build the extension (from the repository root):
-
Package the extension:
-
Install the
.vsixfile: - Open VS Code
- Press
Ctrl+Shift+Pβ "Extensions: Install from VSIX..." - Select the generated
neutron-X.X.X.vsixfile
LSP Server¶
The LSP server (neutron-lsp) must be built and available in your PATH or specified in the extension settings.
-
Build from source:
-
Verify installation:
Usage¶
Autocomplete¶
Start typing and suggestions will appear automatically:
For module functions, first import the module:
Hover Information¶
Hover over any keyword or built-in function to see documentation:
fnβ "Function declaration keyword"printβ "print(value) - Prints a value to stdout"lenβ "len(value) - Returns the length of a string, array, or map"
Running Scripts¶
Click the βΆ Run CodeLens button at the top of any .nt or .ntsc file to execute it.
Alternatively, use the command palette:
- Ctrl+Shift+P β "Neutron: Run Current File"
Formatting¶
Click the π Format CodeLens button or:
- Ctrl+Shift+P β "Neutron: Format Current File"
- Or use the standard VS Code format command: Shift+Alt+F
Safe Mode¶
For type-safe Neutron code, use .ntsc files or safe { } blocks:
// In a .ntsc file, all variables must have type annotations
fn add(a: int, b: int) -> int {
return a + b
}
let x: int = 10 // OK
let y = 20 // ERROR: Missing type annotation
// In a .nt file, use safe blocks for type-checked sections
safe {
let x: int = 10 // OK - inside safe block
let y = 20 // ERROR: Missing type annotation
}
let z = 30 // OK - outside safe block, no type required
Supported File Types¶
| Extension | Language | Description |
|---|---|---|
.nt |
Neutron | Standard Neutron source files |
.ntsc |
Neutron | Type-safe Neutron (Safe Contract) |
.quark |
Quark | Configuration files (TOML-like syntax) |
Quark Configuration Files¶
Quark files use a TOML/INI-like syntax for project configuration:
# Project configuration
[project]
name = "my-app"
version = "1.0.0"
entry = "src/main.nt"
[dependencies]
math = "1.0"
http = "2.1"
[build]
output = "dist/"
optimize = true
Troubleshooting¶
LSP not starting¶
- Check that
neutron-lspis in your PATH or correctly configured - Look at VS Code's Output panel β "Neutron Language Server"
- Ensure the binary has execute permissions:
chmod +x neutron-lsp
No autocomplete suggestions¶
- Ensure the file has a
.nt,.ntsc, or.quarkextension - For module completions, make sure you've imported the module with
use "module_name" - Restart the language server:
Ctrl+Shift+Pβ "Developer: Reload Window"
Formatting not working¶
- Check that the formatter is enabled in your settings
- Try the CodeLens "Format" button directly
- Check the Output panel for any error messages
Safe mode errors not showing¶
- Ensure the file has
.ntscextension for full type-safe mode - For
.ntfiles, code must be inside asafe { }block - Reload the file or restart the language server
Commands¶
| Command | Description |
|---|---|
Neutron: Run Current File |
Execute the current Neutron script |
Neutron: Format Current File |
Format the current file |
Development¶
Building the LSP Server¶
# From repository root
mkdir build && cd build
cmake ..
make neutron-lsp
# The binary will be at build/neutron-lsp
Building the VS Code Extension¶
Testing¶
- Open the
vscode-extensionfolder in VS Code - Press
F5to launch the Extension Development Host - Open a
.ntfile in the new window to test features
Architecture¶
βββββββββββββββββββ JSON-RPC βββββββββββββββββββ
β VS Code β βββββββββββββββββΊ β neutron-lsp β
β Extension β (stdio) β (C++ Server) β
βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β TextMate Grammarβ β Parser/Analyzer β
β (Highlighting) β β (Completions) β
βββββββββββββββββββ βββββββββββββββββββ
The extension uses: - vscode-languageclient to communicate with the LSP server - TextMate grammars for syntax highlighting - JSON-RPC 2.0 protocol over stdio for server communication
Contributing¶
See CONTRIBUTING.md for guidelines on contributing to the LSP and extension.