Skip to main content

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 unified lsp tool supports all LSP operations through a single interface:

Supported Operations

Operation Examples

Go to Definition

Find where a symbol is defined:
Response format (from lsp.ts:208):

Find References

Locate all usages of a symbol:
Response (from lsp.ts:290):

Hover Information

Get documentation and type info:
Response (from lsp.ts:332):
Fetches a user by their unique identifier. @param id - The user’s unique ID @returns A promise resolving to the User object or null if not found
Response (from lsp.ts:370):
Search for symbols across the workspace:
Response (from lsp.ts:415):

Go to Implementation

Find implementations of an interface or abstract method:
Response (from lsp.ts:249):

Call Hierarchy

Prepare Call Hierarchy - Get callable items at a position:
Response (from lsp.ts:505):
Incoming Calls - Find callers of a function:
Response (from lsp.ts:548):
Outgoing Calls - Find functions called by a function:
Response (from lsp.ts:602):

Diagnostics

File Diagnostics - Get errors/warnings for a file:
Response (from lsp.ts:660):
Workspace Diagnostics - Get all diagnostics:
Response (from lsp.ts:700):

Code Actions

Get available quick fixes and refactorings:
Response (from 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:
  1. IDE Extensions: When running in IDE mode (VS Code, etc.)
  2. Manual Configuration: Through Qwen Code settings
  3. Auto-detection: Based on project files

Best Practices

When to Use LSP

The tool description emphasizes (from lsp.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
Avoid LSP for:
  • Searching file contents by pattern (use grep)
  • Finding files by name (use glob)
  • Reading file contents (use read)

Parameter Validation

From lsp.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 a limit 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:
  1. Incorrect file path (use workspace-relative or absolute paths)
  2. Wrong line/character position
  3. Language server not initialized for file type
  4. Symbol not indexed yet
Solution:

Server-Specific Operations

Problem: Need to target specific language server Solution: Use the serverName parameter:

Path Resolution

From lsp.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