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 client::LspClient;
pub use client::HoverResult;
pub use client::format_location;
pub use client::format_diagnostic;
pub use client::format_hover_result;
pub use client::path_to_uri;
pub use manager::LspManager;
pub use manager::find_lsp_config;
pub use manager::load_lsp_config;
pub use progress::LspProgressTracker;
pub use progress::LspInitStatus;
pub use progress::LspProgressCallback;
pub use progress::NoOpProgressCallback;
pub use progress::LoggingProgressCallback;
pub use progress::MultiProgressCallback;
pub use registry::LspClientRegistry;
pub use tools::lsp_tools;
pub use tools::detect_language_from_path;
pub use tools::LspHoverTool;
pub use tools::LspDefinitionTool;
pub use tools::LspReferencesTool;
pub use tools::LspDiagnosticsTool;
pub use transport::LspTransport;
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;
pub use constants::*;

Modules§

client
LSP Client
constants
LSP timeout configuration constants
manager
LSP Manager
progress
LSP Progress Tracking Module
registry
LSP Client Registry
tools
LSP Tools for AI Agents
transport
LSP Transport Layer
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