@@ -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<Path>,
{
- 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
+ ),
+ }
+ }
}
@@ -31,9 +31,7 @@ pub struct LSPClient {
}
impl LSPClient {
- pub async fn setup(
- config: Arc<Config>,
- ) -> anyhow::Result<Self> {
+ pub async fn setup(config: Arc<Config>) -> anyhow::Result<Self> {
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
@@ -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;
@@ -22,8 +22,7 @@ pub struct MCPServer {
}
pub async fn setup(config: Arc<Config>) -> 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());