Skip to main content

Module lsp

Module lsp 

Source
Expand description

LSP (Language Server Protocol) Integration

提供语言服务器连接状态跟踪,用于 TUI 工具栏显示。

§架构概览

┌─────────────────────────────────────────────────────────────┐
│  MatrixCode Agent                                           │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  LSP Manager                                          │   │
│  │  ┌──────────────┐ ┌──────────────┐                   │   │
│  │  │ LspManager   │ │ LspServerInfo│                   │   │
│  │  │ (manager.rs) │ │ (types.rs)   │                   │   │
│  │  └──────────────┘ └──────────────┘                   │   │
│  └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘
                                         │
┌───────────────────────────────────────────│─────────────────┐
│  Language Servers                         │                 │
│  ┌─────────────┐ ┌─────────────┐ ┌───────┴───┐            │
│  │ rust-analyzer│ │ typescript  │ │  python   │            │
│  │ LSP Server  │ │ LSP Server  │ │  LSP      │            │
│  └─────────────┘ └─────────────┘ └───────────┘            │
└─────────────────────────────────────────────────────────────┘

§状态颜色

  • 灰色 (DarkGray):未配置或未启动
  • 绿色 (Green):已连接,正常工作
  • 红色 (Red):连接错误

§使用示例

use matrixcode_core::lsp::{LspManager, LspServerInfo, LspServerStatus};

// 创建管理器
let manager = LspManager::new();

// 添加服务器配置
manager.add_server(LspServerConfig::new("rust-analyzer", "rust"));

// 获取状态列表(用于 TUI 显示)
let infos = manager.server_infos().await;
for info in infos {
    println!("{}: {}", info.name, info.status.label());
}

Re-exports§

pub use manager::LspManager;
pub use manager::find_lsp_config;
pub use manager::load_lsp_config;
pub use types::LspConfig;
pub use types::LspServerConfig;
pub use types::LspServerInfo;
pub use types::LspServerStatus;
pub use types::default_lsp_config;
pub use types::default_python_config;
pub use types::default_rust_analyzer_config;
pub use types::default_typescript_config;

Modules§

manager
LSP Manager
types
LSP Types

Functions§

get_active_lsp_servers
Get active (connected) LSP servers
should_inject_lsp_context
Check if LSP context should be injected into system prompt