2.2 KiB
2.2 KiB
title, type, tags, sources, last_updated
| title | type | tags | sources | last_updated | |||||
|---|---|---|---|---|---|---|---|---|---|
| LSPOrchestrator | concept |
|
|
2026-04-29 |
Definition
LSP 编排器(LSP Orchestrator)是在 graphd 架构中协调多个语言服务器并发运行的中间层,负责统一管理不同语言的 LSP 客户端、正确处理各服务器的能力协商、并将对异构 LSP 响应格式标准化为统一格式。
Core Mechanism
Client Initialization
class LSPOrchestrator {
async initialize(projectRoot: string) {
const tsClient = new LanguageClient('typescript', {
command: 'typescript-language-server',
args: ['--stdio'],
rootPath: projectRoot
});
const phpClient = new LanguageClient('php', {
command: 'intelephense',
args: ['--stdio'],
rootPath: projectRoot
});
await Promise.all([
this.initializeClient('typescript', tsClient),
this.initializeClient('php', phpClient)
]);
}
}
Multi-Language Coordination
- 并行初始化:所有语言服务器并发启动
- 能力协商:为每个服务器独立检查
ServerCapabilities - 语言检测:根据文件扩展名路由到对应语言服务器
- 请求批处理:合并相邻请求以减少往返开销
- 缓存策略:积极缓存但精确失效
Capability-Negotiation Pattern
async getDefinition(uri: string, position: Position): Promise<Location[]> {
const lang = this.detectLanguage(uri);
const client = this.clients.get(lang);
if (!client || !this.capabilities.get(lang)?.definitionProvider) {
return [];
}
return client.sendRequest('textDocument/definition', {
textDocument: { uri },
position
});
}
Performance Optimization
- 请求批处理:合并多个相邻 LSP 请求
- 零拷贝技术:内存映射文件和大数据集
- Worker Threads:CPU 密集型操作分流到 Worker
- 锁无关数据结构:并发访问无锁化
Connections
- LSPOrchestrator ← part_of ← GraphDaemon
- LSPOrchestrator ← coordinates ← LanguageServerProtocol
- LSPOrchestrator ← feeds ← SemanticCodeGraph
- LSPOrchestrator ← uses ← IncrementalGraphUpdate