diff --git a/src/config.rs b/src/config.rs index db983c37ab4216eea1c82aa752e312cfc662a0b6..b1a954a27ff24a63f256eb2aa283f51ebe82c709 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,11 @@ -use async_gen::{AsyncIter, r#gen}; use anyhow::Context; +use async_gen::{AsyncIter, r#gen}; use clap::Parser; use rmcp::serde_json; -use std::{fs::FileType, path::{Path, PathBuf}}; +use std::{ + fs::FileType, + path::{Path, PathBuf}, +}; #[derive(Parser, Debug)] #[command(version, about)] @@ -21,7 +24,7 @@ pub struct Command { pub struct Config { pub lsp_server_command: Command, - /// An absolute path pointing to the root of the project on disk. + /// An absolute path pointing to the root of the project on disk. pub project_root: PathBuf, } @@ -38,11 +41,16 @@ impl Config { where P: AsRef, { - let joined = self.project_root.join(&path); - match tokio::fs::try_exists(joined.as_path()).await { - Ok(true) => anyhow::Ok(Some(joined)), - Ok(false) => anyhow::Ok(None), - Err(err) => anyhow::bail!("Could not look for path {:?} in project {:?}, error: {}", path.as_ref(), self.project_root, err) - } - } + let joined = self.project_root.join(&path); + match tokio::fs::try_exists(joined.as_path()).await { + Ok(true) => anyhow::Ok(Some(joined)), + Ok(false) => anyhow::Ok(None), + Err(err) => anyhow::bail!( + "Could not look for path {:?} in project {:?}, error: {}", + path.as_ref(), + self.project_root, + err + ), + } + } } diff --git a/src/lsp/client.rs b/src/lsp/client.rs index e71cb2a2e4df49447de82150f987e97a38e88b53..b3b157ab7a36954d2cb098ac78fb2030e3cb5a68 100644 --- a/src/lsp/client.rs +++ b/src/lsp/client.rs @@ -31,9 +31,7 @@ pub struct LSPClient { } impl LSPClient { - pub async fn setup( - config: Arc, - ) -> anyhow::Result { + pub async fn setup(config: Arc) -> anyhow::Result { let child = ProcessCommand::new(&config.lsp_server_command.command) .args(&config.lsp_server_command.args) .current_dir(&config.project_root) @@ -42,13 +40,19 @@ impl LSPClient { .stderr(Stdio::inherit()) .kill_on_drop(true) .spawn() - .expect(format!("Failed to start lsp: {} {:?}", &config.lsp_server_command.command, &config.lsp_server_command.args).as_ref()); + .expect( + format!( + "Failed to start lsp: {} {:?}", + &config.lsp_server_command.command, &config.lsp_server_command.args + ) + .as_ref(), + ); let config_clone = config.clone(); let (mainloop, mut server) = async_lsp::MainLoop::new_client(move |_server| { let mut router = Router::new(LSPClientState { config: config_clone, - indexed_tx: None + indexed_tx: None, }); router diff --git a/src/main.rs b/src/main.rs index 3b3cd6ce42f303652390fb1d489f905bf24a2ebf..3e54ac612d12824caf4ca8cb4e92c991c17373c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,8 @@ mod config; mod lsp; mod mcp; -use std::sync::Arc; use clap::Parser; +use std::sync::Arc; use config::{CommandLineArgs, Config}; use tracing_subscriber::EnvFilter; diff --git a/src/mcp/server.rs b/src/mcp/server.rs index e8820579df0aa3649ab813c62d1131386e0d0667..f37be84e3a8311522c3af25c92ba30ab0c7c17e6 100644 --- a/src/mcp/server.rs +++ b/src/mcp/server.rs @@ -22,8 +22,7 @@ pub struct MCPServer { } pub async fn setup(config: Arc) -> anyhow::Result<(MCPServer, LSPClient)> { - let lsp_client = LSPClient::setup(config.clone()) - .await?; + let lsp_client = LSPClient::setup(config.clone()).await?; let server = MCPServer::new(config, lsp_client.server.clone()); diff --git a/src/mcp/tools/read.rs b/src/mcp/tools/read.rs index 534eccee818babb378b533c18cf6f25d02bcc8d0..5acc33a9f4d4e8cee4d8f09ba066af1d110a2c96 100644 --- a/src/mcp/tools/read.rs +++ b/src/mcp/tools/read.rs @@ -1,3 +1,5 @@ +/// The implementation of this tool draws heavily from Zed's +/// See use std::path::PathBuf; use async_lsp::LanguageServer;