feat(lsp): implement LSP client and server management

- Added LspClient for handling communication with LSP servers, including methods for initialization, notifications, and requests.
- Introduced LspManager to manage multiple LSP server connections, allowing for connection, disconnection, and retrieval of server capabilities.
- Created tools for connecting to LSP servers, retrieving diagnostics, hover information, code completion, definitions, and references.
- Enhanced UI rendering to display token usage and settings in the overlay.
- Updated status bar to show current token usage and selected provider/model.
This commit is contained in:
asepharyana
2026-07-12 13:40:58 +07:00
parent 8ad042139e
commit abc7a58e31
19 changed files with 1317 additions and 60 deletions
+17 -1
View File
@@ -1,6 +1,7 @@
//! Tool trait, execution context, and the registry of all 28 built-in tools.
//! Tool trait, execution context, and the registry of all built-in tools.
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use serde_json::Value;
use anyhow::Result;
@@ -9,6 +10,7 @@ pub mod fs;
pub mod git_cred;
pub mod git_operator;
pub mod git_worktree;
pub mod lsp;
pub mod memory;
pub mod plan;
pub mod search;
@@ -46,6 +48,7 @@ pub struct ToolCtx {
pub dir_cache: std::sync::Arc<tokio::sync::RwLock<super::app::state::misc::DirCache>>,
pub origin: crate::app::state::types::Origin,
pub graduated_checks: Vec<GraduatedCheck>,
pub lsp_manager: Arc<Mutex<crate::app::lsp::LspManager>>,
}
/// Find which graduated checks apply to a given file path/content pair.
@@ -81,6 +84,7 @@ pub struct ToolCtxBuilder {
pub dir_cache: std::sync::Arc<tokio::sync::RwLock<super::app::state::misc::DirCache>>,
pub origin: crate::app::state::types::Origin,
pub graduated_checks: Vec<GraduatedCheck>,
pub lsp_manager: Arc<Mutex<crate::app::lsp::LspManager>>,
}
impl Default for ToolCtxBuilder {
@@ -94,6 +98,7 @@ impl Default for ToolCtxBuilder {
dir_cache: std::sync::Arc::new(tokio::sync::RwLock::new(super::app::state::misc::DirCache::new())),
origin: crate::app::state::types::Origin::Main,
graduated_checks: Vec::new(),
lsp_manager: Arc::new(Mutex::new(crate::app::lsp::LspManager::new())),
}
}
}
@@ -103,6 +108,9 @@ impl ToolCtxBuilder {
pub fn session_dir(mut self, v: PathBuf) -> Self { self.session_dir = v; self }
/// Set the origin (main process vs. daemon-attached).
pub fn origin(mut self, v: crate::app::state::types::Origin) -> Self { self.origin = v; self }
/// Set the lsp_manager.
#[allow(dead_code)]
pub fn lsp_manager(mut self, v: Arc<Mutex<crate::app::lsp::LspManager>>) -> Self { self.lsp_manager = v; self }
/// Consume the builder and produce the final `ToolCtx`.
pub fn build(self) -> ToolCtx {
ToolCtx {
@@ -114,6 +122,7 @@ impl ToolCtxBuilder {
dir_cache: self.dir_cache,
origin: self.origin,
graduated_checks: self.graduated_checks,
lsp_manager: self.lsp_manager,
}
}
}
@@ -149,6 +158,13 @@ pub fn all_tools() -> Vec<Box<dyn Tool>> {
Box::new(super::tool::utility::dir_cache_update::DirCacheUpdate),
Box::new(super::tool::utility::pong::Pong),
Box::new(super::tool::utility::todowrite::Todowrite),
Box::new(super::tool::lsp::LspConnect),
Box::new(super::tool::lsp::LspDiagnostics),
Box::new(super::tool::lsp::LspHover),
Box::new(super::tool::lsp::LspCompletion),
Box::new(super::tool::lsp::LspDefinition),
Box::new(super::tool::lsp::LspReferences),
Box::new(super::tool::lsp::LspDisconnect),
]
}