Language Server Protocol Integration
Qwen Code includes first-class support for the Language Server Protocol (LSP), enabling precise code navigation, intelligent symbol lookup, and advanced refactoring capabilities.Overview
LSP provides Qwen Code with:- Go to Definition: Navigate to where symbols are defined
- Find References: Locate all usages of a symbol
- Hover Information: Get documentation and type information
- Document Symbols: List all symbols in a file
- Workspace Symbols: Search for symbols across the entire codebase
- Go to Implementation: Find implementations of interfaces
- Call Hierarchy: Analyze function call relationships
- Diagnostics: Access compiler/linter errors and warnings
- Code Actions: Get available quick fixes and refactorings
LSP Tool Usage
The unifiedlsp tool supports all LSP operations through a single interface:
Supported Operations
Operation Examples
Go to Definition
Find where a symbol is defined:lsp.ts:208):
Find References
Locate all usages of a symbol:lsp.ts:290):
Hover Information
Get documentation and type info:lsp.ts:332):
lsp.ts:370):
Workspace Symbol Search
Search for symbols across the workspace:lsp.ts:415):
Go to Implementation
Find implementations of an interface or abstract method:lsp.ts:249):
Call Hierarchy
Prepare Call Hierarchy - Get callable items at a position:lsp.ts:505):
lsp.ts:548):
lsp.ts:602):
Diagnostics
File Diagnostics - Get errors/warnings for a file:lsp.ts:660):
lsp.ts:700):
Code Actions
Get available quick fixes and refactorings:lsp.ts:783):
Configuration
Enabling LSP
LSP is automatically enabled when language servers are configured. The tool checks:Server Configuration
Language servers are typically configured through:- IDE Extensions: When running in IDE mode (VS Code, etc.)
- Manual Configuration: Through Qwen Code settings
- Auto-detection: Based on project files
Best Practices
When to Use LSP
The tool description emphasizes (fromlsp.ts:1021):
ALWAYS use LSP as the PRIMARY tool for code intelligence queries when available. Do NOT use grep_search or glob first.Use LSP for:
- Finding symbol definitions
- Analyzing code structure
- Understanding type information
- Refactoring code
- Diagnosing errors
- Searching file contents by pattern (use grep)
- Finding files by name (use glob)
- Reading file contents (use read)
Parameter Validation
Fromlsp.ts:1153, the tool validates:
Line/Character Coordinates
Important: LSP uses 1-based line and character numbers in the tool interface, but converts to 0-based internally:Result Limits
All operations support alimit parameter with sensible defaults:
Troubleshooting
LSP Not Available
Problem: Tool returns “LSP is unavailable” Solution: Ensure language servers are configured:No Results Returned
Problem: Operations return empty results Possible causes:- Incorrect file path (use workspace-relative or absolute paths)
- Wrong line/character position
- Language server not initialized for file type
- Symbol not indexed yet
Server-Specific Operations
Problem: Need to target specific language server Solution: Use theserverName parameter:
Path Resolution
Fromlsp.ts:847, paths are resolved as:
Integration Examples
Symbol Navigation Workflow
Error Analysis Workflow
Call Graph Analysis
Source Code References
- LSP tool implementation:
packages/core/src/tools/lsp.ts - LSP types:
packages/core/src/lsp/types.ts - Configuration:
packages/core/src/config/config.ts:64
