lsp-integration
LSP Integration Skill
You are an expert in leveraging Language Server Protocol (LSP) for semantic code understanding. LSP provides 100x faster and more accurate code exploration than text-based grep searches.
Overview
LSP servers understand code semantically - they know about types, symbols, references, and relationships between code elements. This enables precise navigation and refactoring that text search cannot achieve.
Supported Languages
| Language | LSP Server | Install |
|---|---|---|
| TypeScript/JavaScript | typescript-language-server |
npm install -g typescript-language-server typescript |
| Python | python-lsp-server (pylsp) |
pip install python-lsp-server |
| Go | gopls |
go install golang.org/x/tools/gopls@latest |
| Rust | rust-analyzer |
Via rustup or standalone |
| Java | jdtls |
Eclipse JDT Language Server |
| C# | omnisharp |
.NET SDK |
Key Operations
1. Go to Definition
Navigate to where a symbol is defined.
# Using TypeScript language server
npx ts-node --eval "
const ts = require('typescript');
// Find definition of symbol at position
"
Use case: "Where is this function defined?" → Find exact location in codebase.
2. Find All References
Find every place a symbol is used.
Critical for refactoring: Before renaming or changing a function, ALWAYS find all references to understand impact.
# Find all usages of a function/variable/class
# LSP tracks semantic references, not just text matches
Use case: "What will break if I change this interface?" → Find all implementations and usages.
3. Document Symbols
Get structured view of all symbols in a file.
Use case: "What functions/classes are in this file?" → Get hierarchy without parsing.
4. Hover Information
Get type information and documentation for any symbol.
Use case: "What type does this variable have?" → Get inferred or declared type.
5. Diagnostics
Get compilation errors and warnings.
Use case: "Are there any type errors?" → Real-time error checking.
When to Use LSP vs Grep
| Task | Use LSP | Use Grep |
|---|---|---|
| Find function definition | ✅ Precise | ⚠️ May find wrong match |
| Find all references | ✅ Semantic | ⚠️ Misses renamed imports |
| Search for text pattern | ❌ Not designed for this | ✅ Fast text search |
| Understand type hierarchy | ✅ Full inheritance chain | ❌ Cannot determine |
| Check for type errors | ✅ Compiler-accurate | ❌ Impossible |
| Find files by name | ❌ Overkill | ✅ Use Glob |
Best Practices
1. Always Use findReferences Before Refactoring
❌ WRONG: Grep for function name → rename → hope nothing breaks
✅ RIGHT: LSP findReferences → understand all usages → safe rename
2. Use goToDefinition Instead of Grep
❌ WRONG: grep -r "function processOrder" .
✅ RIGHT: LSP goToDefinition → exact location, handles imports/exports
3. Combine with Explore Agent
For complex exploration tasks, combine LSP operations with the Explore agent:
1. LSP: Find all references to deprecated function
2. Explore: Understand migration patterns in codebase
3. LSP: Navigate to each usage for refactoring
TypeScript/JavaScript Specific
Setup
# Install globally
npm install -g typescript-language-server typescript
# Verify installation
typescript-language-server --version
Common Operations
Find where interface is implemented:
// LSP findReferences on interface → shows all implementing classes
Check type at position:
// LSP hover → shows inferred type, even for complex generics
Find unused exports:
// LSP diagnostics + findReferences → exports with 0 references
Python Specific
Setup
pip install python-lsp-server
# Optional: Add type checking
pip install pylsp-mypy
Common Operations
Find class hierarchy:
# LSP can show base classes and subclasses
Check import resolution:
# LSP resolves imports even with complex __init__.py structures
Integration with SpecWeave
In CLAUDE.md (already documented)
LSP operations are recommended in the SpecWeave workflow:
- Use
findReferencesbefore any refactoring - Use
goToDefinitionfor code navigation - Use
getDiagnosticsto check for errors
Workflow Example
- Before implementing: Use LSP to understand existing code structure
- During implementation: Use diagnostics to catch errors early
- Before commit: Use findReferences to verify no broken usages
- Code review: Use LSP to trace data flow through system
Troubleshooting
LSP Server Not Starting
# Check if server is installed
which typescript-language-server
which pylsp
which gopls
# Check for initialization errors
typescript-language-server --stdio 2>&1 | head -20
Slow Performance
- Exclude
node_modulesand build directories - Ensure
tsconfig.jsonor equivalent is properly configured - Increase memory limits for large projects
Missing References
- Ensure project is properly typed
- Check that all dependencies have type definitions
- Verify language server has indexed the project
Token Budget
- LSP setup instructions: 200-300 tokens
- Single operation explanation: 100-200 tokens
- Full workflow: 400-600 tokens
NEVER exceed 2000 tokens per response!
More from anton-abyzov/specweave
technical-writing
Technical writing expert for API documentation, README files, tutorials, changelog management, and developer documentation. Covers style guides, information architecture, versioning docs, OpenAPI/Swagger, and documentation-as-code. Activates for technical writing, API docs, README, changelog, tutorial writing, documentation, technical communication, style guide, OpenAPI, Swagger, developer docs.
45spec-driven-brainstorming
Spec-driven brainstorming and product discovery expert. Helps teams ideate features, break down epics, conduct story mapping sessions, prioritize using MoSCoW/RICE/Kano, and validate ideas with lean startup methods. Activates for brainstorming, product discovery, story mapping, feature ideation, prioritization, MoSCoW, RICE, Kano model, lean startup, MVP definition, product backlog, feature breakdown.
43kafka-architecture
Apache Kafka architecture expert for cluster design, capacity planning, and high availability. Use when designing Kafka clusters, choosing partition strategies, or sizing brokers for production workloads.
34docusaurus
Docusaurus 3.x documentation framework - MDX authoring, theming, versioning, i18n. Use for documentation sites or spec-weave.com.
29frontend
Expert frontend developer for React, Vue, Angular, and modern JavaScript/TypeScript. Use when creating components, implementing hooks, handling state management, or building responsive web interfaces. Covers React 18+ features, custom hooks, form handling, and accessibility best practices.
29reflect
Self-improving AI memory system that persists learnings across sessions in CLAUDE.md. Use when capturing corrections, remembering user preferences, or extracting patterns from successful implementations. Enables continual learning without starting from zero each conversation.
27