Sanctifier now provides an editor-agnostic Language Server Protocol (LSP) implementation, enabling real-time security analysis across any LSP-capable editor: VSCode, Neovim, Helix, Zed, JetBrains IDEs, and more.
The Sanctifier LSP server (sanctifier lsp) provides:
- Real-time Diagnostics: Immediate feedback on security issues as you type
- Code Actions: Quick fixes for authorization gaps and arithmetic overflow patterns
- Hover Information: Detailed descriptions of detected issues
- Cross-Editor Support: Works with any editor supporting the Language Server Protocol
-
Build or install
sanctifier:cargo build --bin sanctifier --release # Binary will be at: ./target/release/sanctifier -
Or install via cargo:
cargo install --path tooling/sanctifier-cli
sanctifier lspOr with debug logging:
sanctifier lsp --debugThe server listens on stdin/stdout and outputs diagnostic results over the LSP protocol.
Update your VSCode settings to use the Sanctifier LSP:
.vscode/settings.json or User Settings:
{
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"lsp.languageServers": {
"sanctifier": {
"command": "sanctifier",
"args": ["lsp"],
"filetypes": ["rust"],
"description": "Soroban security analysis"
}
}
}Or use the VS Code LSP Client extension to connect to the server.
Use the built-in LSP client with Neovim's init.lua:
vim.lsp.start({
name = "sanctifier",
cmd = { "sanctifier", "lsp" },
root_dir = vim.fn.getcwd(),
filetypes = { "rust" },
})Or use a plugin like nvim-lspconfig:
require('lspconfig.configs').sanctifier = {
default_config = {
cmd = { 'sanctifier', 'lsp' },
filetypes = { 'rust' },
root_dir = require('lspconfig').util.root_pattern('Cargo.toml'),
}
}
require('lspconfig').sanctifier.setup({})Add to .helix/languages.toml:
[[language]]
name = "rust"
language-servers = ["rust-analyzer", "sanctifier"]
[language-server.sanctifier]
command = "sanctifier"
args = ["lsp"]Configure in Zed's settings:
{
"language_servers": {
"sanctifier": {
"command": "sanctifier",
"args": ["lsp"]
}
},
"languages": {
"Rust": {
"language_servers": ["rust-analyzer", "sanctifier"]
}
}
}- Install the LSP Support plugin (if not already installed)
- Go to Settings → Languages & Frameworks → Language Servers
- Click + to add a new server:
- Language: Rust
- Extension: rs
- Command:
sanctifier lsp
- Apply and restart
The LSP server publishes diagnostics with the following error codes:
| Code | Severity | Issue | Suggestion |
|---|---|---|---|
| S001 | Warning | Auth Gap | Function modifies state without require_auth |
| S002 | Warning | Panic Usage | Use of panic!(), .unwrap(), or .expect() |
| S003 | Warning | Arithmetic Overflow | Unchecked arithmetic operations |
| S004 | Error/Warning | Ledger Size | Structure exceeds allocated space limits |
| S006 | Warning | Unsafe Pattern | Risky code patterns detected |
| S007 | Info | Custom Rule | Custom regex rule match |
When you open a Rust file in an LSP-capable editor:
Line 42: Function 'transfer' modifies state without authorization check.
Add require_auth or require_auth_for_args. [S001]
Line 50: Unchecked arithmetic operation '+' in function 'mint'.
Use `.checked_add(rhs)` or `.saturating_add(rhs)` [S003]
The LSP server provides quick fixes for common issues:
- Title:
Add require_auth to function '<name>' - Action: Suggests adding authorization checks to privileged functions
- Title:
Use checked_<op> instead of '<op>' - Action: Suggests replacing unsafe arithmetic with checked versions
| Method | Type | Description |
|---|---|---|
initialize |
Request | Initialize the server handshake |
shutdown |
Request | Graceful server shutdown |
textDocument/didOpen |
Notification | File opened in editor |
textDocument/didChange |
Notification | File content changed |
textDocument/didClose |
Notification | File closed in editor |
textDocument/codeAction |
Request | Request code actions for range |
The server advertises these capabilities:
{
"capabilities": {
"textDocumentSync": 1,
"diagnosticProvider": {
"interFileDependencies": false,
"workspaceDiagnostics": false
},
"codeActionProvider": true,
"hoverProvider": true
}
}Test the LSP server directly with stdio:
# Start the server
sanctifier lsp --debug
# In another terminal, send an initialize request:
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | \
(echo 'Content-Length: 65'; echo ''; cat) | \
nc localhost 9000Use vscode-test-cli for automated testing:
cd vscode-extension
npm install
npm testTest with Neovim's built-in LSP client:
nvim +LSPStart <your_soroban_contract.rs>Monitor LSP activity:
:LspLogThe LSP server respects .sanctify.toml configuration when present:
[sanctifier]
enabled_rules = ["auth_gaps", "panics", "arithmetic"]
ledger_limit = 65536
approaching_threshold = 0.8
strict_mode = false
[[rules]]
name = "custom_pattern"
pattern = "unsafe\s+\{.*\}"
severity = "warning"- Startup: < 100ms
- Diagnostic Scan: < 500ms for typical contracts (< 5000 LOC)
- Memory: ~20-50 MB base, scales with open document count
-
Verify
sanctifieris in your PATH:which sanctifier
-
Test directly:
sanctifier lsp --debug 2>&1 | head -20
-
Check editor LSP configuration logs
- Ensure the file is recognized as Rust (
*.rs) - Check that the file content is valid Rust syntax
- Enable debug logging in LSP server:
# Kill current server and restart with: sanctifier lsp --debug - View server output in editor's LSP debug console
If analysis is slow:
- Check file size (> 100KB might be slow)
- Ensure no large generated files are being analyzed
- Configure
ignore_pathsin.sanctify.toml - Check system resources (CPU, memory)
The Sanctifier LSP follows the standard LSP specification (v3.17):
Editor ←→ LSP Client (Built-in)
↓ stdio
Sanctifier LSP Server
↓
sanctifier-core
↓
Analysis Engines:
- Auth Gap Scanner
- Panic Detector
- Arithmetic Overflow Analyzer
- Storage Size Estimator
- Custom Rule Matcher
# Build debug binary
cargo build --bin sanctifier
# Start server with debug logging
./target/debug/sanctifier lsp --debug
# Test with a sample contract
cat contracts/token-with-bugs/src/lib.rs | \
./target/debug/sanctifier lsp --debug###Contributing
To extend the LSP server:
- Add new diagnostic in src/commands/lsp.rs
- Implement
analyze_document()extension - Add corresponding code action in
get_code_actions() - Test with editor client
- Update this documentation
Sanctifier LSP Server is licensed under MIT or Apache 2.0 (see LICENSE)