Editor Support (LSP)
The Nic compiler includes a Language Server Protocol (LSP) implementation for IDE integration.
Features
| Feature | Description |
|---|---|
| Diagnostics | Real-time parse and type errors |
| Hover | Type information and documentation on hover |
| Go to Definition | Jump to symbol definitions (cross-module) |
| Find References | Find all uses of a symbol |
| Document Outline | Symbols, structs, classes, enums, traits |
| Semantic Highlighting | Context-aware syntax highlighting |
| Auto-completion | Symbol and import suggestions |
VS Code Setup
Install the Extension
- Get the Nic extension from the VS Code marketplace, or install manually:
cd extensions/vscode
npm install
npm run package
code --install-extension nic-language-*.vsix- The extension automatically starts the LSP server when you open
.nicfiles.
Extension Settings
Configure in VS Code settings (settings.json):
{
"nic.compiler.path": "nicc",
"nic.trace.server": "verbose"
}| Setting | Default | Description |
|---|---|---|
nic.compiler.path | nicc | Path to nicc executable |
nic.trace.server | off | LSP message tracing (off, messages, verbose) |
Neovim Setup
Using nvim-lspconfig
Add to your Neovim configuration:
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
-- Define Nic language server
if not configs.nic then
configs.nic = {
default_config = {
cmd = { 'nicc', 'lsp' },
filetypes = { 'nic' },
root_dir = lspconfig.util.root_pattern('nic.toml', '.git'),
settings = {},
},
}
end
-- Enable the server
lspconfig.nic.setup({
on_attach = function(client, bufnr)
-- Your on_attach configuration
end,
})File Type Detection
Add to your init.lua:
vim.filetype.add({
extension = {
nic = 'nic',
},
})Other Editors
Any editor supporting LSP can use the Nic language server:
nicc lspThe server communicates via stdin/stdout using the Language Server Protocol.
Helix
Add to ~/.config/helix/languages.toml:
[[language]]
name = "nic"
scope = "source.nic"
file-types = ["nic"]
roots = ["nic.toml"]
language-server = { command = "nicc", args = ["lsp"] }Sublime Text
Install the LSP package, then add to settings:
{
"clients": {
"nic": {
"command": ["nicc", "lsp"],
"selector": "source.nic"
}
}
}Debugging the LSP
Enable Debug Logging
NICC_LSP_DEBUG=1 nicc lspOr use a custom log file:
nicc lsp --log /tmp/nicc-lsp.logDefault log location: ~/.nicc/logs/lsp.log
Log Contents
Debug logs include:
- Requests/Responses: All LSP message exchanges
- File Changes: Document open, change, save events
- Diagnostics: Errors and warnings sent to editor
- Module Graph: Import resolution and dependencies
- Cache Operations: Hit/miss information
- Timing: Compilation duration for performance analysis
Example Debug Session
# Terminal 1: Start LSP with debugging
NICC_LSP_DEBUG=1 nicc lsp
# Terminal 2: Watch the log
tail -f ~/.nicc/logs/lsp.logTroubleshooting
LSP Not Starting
Verify nicc is in PATH:
bashwhich nicc nicc --versionCheck extension logs (VS Code: Output > Nic Language Server)
Try running manually:
bashecho '{"jsonrpc":"2.0","method":"initialize","params":{},"id":1}' | nicc lsp
No Diagnostics
Ensure standard library is installed:
bashls ~/.nicc/std/Check for prelude errors:
bashnicc --sast yourfile.nicEnable debug logging to see what's happening
Slow Performance
Check file size (very large files may be slow)
Review debug log for timing:
[DEBUG] Compilation took 150msEnsure incremental compilation is working (check for cache hits)
Go to Definition Not Working
Ensure the target module is compiled without errors
Check module imports are correct:
nicimport std.io; // Must match actual module pathCross-module navigation requires all files to type-check successfully
Hover Not Showing Types
File must compile without errors
Cursor must be on a valid identifier
Check debug log for hover requests
LSP Capabilities
The Nic LSP server advertises these capabilities:
{
"textDocumentSync": "incremental",
"completionProvider": { "triggerCharacters": ["."] },
"hoverProvider": true,
"definitionProvider": true,
"referencesProvider": true,
"documentSymbolProvider": true,
"semanticTokensProvider": { "full": true }
}Protocol Details
Initialization
The server sends standard LSP initialization responses. No special configuration is required.
Text Synchronization
The server uses incremental text synchronization for efficiency. On each change:
- Parse the updated file
- Re-type-check affected modules
- Send updated diagnostics
Semantic Tokens
Token types supported:
namespace- Module namestype- Type namesclass- Class namesenum- Enum namesfunction- Function namesparameter- Parametersvariable- Variablesproperty- Struct fieldskeyword- Language keywordsstring,number- Literalscomment- Comments
See Also
- CLI Commands -
nicc lspcommand - Debugging - LSP debug logging