Debugging the LSP Server
Follow this guide when debugging LSP issues.
Quick Diagnostics
1. Check if LSP Binary Exists
bash
ls -la target/debug/graphql-lsp
If missing, rebuild:
bash
cargo build
2. Test LSP Directly
bash
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | target/debug/graphql-lsp
Should return a valid JSON-RPC response.
Logging
Enable Debug Logging
bash
RUST_LOG=debug target/debug/graphql-lsp
Module-Specific Logging
bash
# LSP layer only RUST_LOG=graphql_lsp=debug target/debug/graphql-lsp # Analysis layer RUST_LOG=graphql_analysis=debug target/debug/graphql-lsp # Multiple modules RUST_LOG=graphql_lsp=debug,graphql_analysis=info,graphql_hir=trace target/debug/graphql-lsp
Log Levels
| Level | Use For |
|---|---|
| ERROR | Critical failures only |
| WARN | Non-fatal issues |
| INFO | High-level operations |
| DEBUG | Detailed operations, timing |
| TRACE | Deep debugging |
OpenTelemetry Tracing
For performance issues, use distributed tracing:
1. Build with OpenTelemetry
bash
cargo build --features otel
2. Start Jaeger
bash
docker run -d --name jaeger \ -p 4317:4317 \ -p 16686:16686 \ jaegertracing/all-in-one:latest
3. Run with Tracing
bash
OTEL_TRACES_ENABLED=1 target/debug/graphql-lsp
4. View Traces
Open http://localhost:16686 in your browser.
Look for:
- •Long spans indicating slow operations
- •Missing spans indicating crashes
- •Repeated spans indicating unnecessary recomputation
Common Issues
LSP Not Responding
Symptoms: Editor shows no diagnostics, features don't work
Debug steps:
- •Check VSCode Output → GraphQL for errors
- •Verify LSP binary path in extension settings
- •Test LSP directly (see above)
- •Check for panics in logs
Hangs / Deadlocks
Symptoms: LSP stops responding, CPU stays high
Likely cause: Salsa deadlock from concurrent access
Debug steps:
- •Enable RUST_LOG=debug
- •Look for "acquiring lock" messages without corresponding releases
- •Check for snapshot not being dropped before setter calls
- •Consult
salsa.mdagent for deadlock patterns
Common fix: Ensure snapshots are dropped before mutations:
rust
// WRONG
let snapshot = db.clone();
let result = snapshot.some_query();
db.set_input(...); // Deadlock!
// RIGHT
let result = {
let snapshot = db.clone();
snapshot.some_query()
}; // snapshot dropped
db.set_input(...); // Safe
Incorrect Diagnostics
Symptoms: Wrong errors, missing errors, stale errors
Debug steps:
- •Check file is registered in project
- •Verify schema is loaded correctly
- •Check fragment resolution with
all_fragments()query - •Look for cache invalidation issues
Slow Performance
Symptoms: Laggy editor, delayed diagnostics
Debug steps:
- •Use OpenTelemetry to identify hot spots
- •Check if warm queries are being recomputed (should be cached)
- •Look for O(n) operations that should be O(1)
- •Run benchmarks:
cargo bench
Expected performance:
- •Warm queries: < 1ms
- •Cold parse: < 10ms for typical files
- •Full validation: < 100ms for typical project
VSCode Extension Issues
Symptoms: Extension not activating, wrong files targeted
Debug steps:
- •Check extension logs: View → Output → GraphQL
- •Verify
documentSelectorincludes target languages - •Check grammar injection for syntax highlighting
- •Rebuild extension:
cd editors/vscode && npm run compile
SME Agents to Consult
- •salsa.md: For deadlocks, cache issues, incremental computation bugs
- •lsp.md: For protocol violations, response format issues
- •rust-analyzer.md: For architectural debugging patterns
- •vscode-extension.md: For extension-specific issues