From 04c76d88d85612eb274e6dc10992b55d97cfd113 Mon Sep 17 00:00:00 2001 From: Sofus Addington Date: Tue, 30 Sep 2025 10:40:10 +0200 Subject: [PATCH] Removes `--no-open`, in favour of returning path for executable or dll when downloading --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 64 +++++++++++++++++++++------------------------------ src/server.rs | 9 ++++++-- 4 files changed, 35 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7ff4f7..a5d6fe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,7 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "csharp-language-server" -version = "0.6.0" +version = "0.7.0" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 0ceb721..a10c4b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "csharp-language-server" -version = "0.6.0" +version = "0.7.0" edition = "2024" authors = ["Sofus Addington"] description = "A tool that simplifies installation and running C# language server" diff --git a/src/main.rs b/src/main.rs index 9338eff..6f24e36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ struct Args { #[arg(short, long, default_value_t = true)] remove_old_server_versions: bool, - /// Download Microsoft.CodeAnalysis.LanguageServer and exit + /// Download Microsoft.CodeAnalysis.LanguageServer. Returns path to dll (macos) or executable (win and linux) #[arg(long, default_value_t = false)] download: bool, @@ -34,10 +34,6 @@ struct Args { /// Override project(s) (.csproj) path(s). Absolute path. Solution path takes precedence #[arg(short, long)] project_paths: Option>, - - /// Disable sending any "open" commands. - #[arg(short, long, default_value_t = false)] - no_open: bool, } #[tokio::main] @@ -47,11 +43,8 @@ async fn main() { let directory_path = args.directory.map(|dir| PathBuf::from_str(&dir).unwrap()); if args.download { - println!("Downloading language server"); - - download_server(version, args.remove_old_server_versions, directory_path).await; - - println!("Done!"); + let path = download_server(version, args.remove_old_server_versions, directory_path).await; + println!("{}", path.to_string_lossy()); return; } @@ -69,38 +62,33 @@ async fn main() { let stdin_to_stream = async { let mut stdin = BufReader::new(stdin); - if !args.no_open { - loop { - let mut buffer = vec![0; 6000]; - let bytes_read = stdin - .read(&mut buffer) - .await - .expect("Unable to read incoming client notification"); - if bytes_read == 0 { - break; // EOF reached - } - server_stdin - .write_all(&buffer[..bytes_read]) - .await - .expect("Unable to forward client notification to server"); + loop { + let mut buffer = vec![0; 6000]; + let bytes_read = stdin + .read(&mut buffer) + .await + .expect("Unable to read incoming client notification"); + if bytes_read == 0 { + break; // EOF reached + } + server_stdin + .write_all(&buffer[..bytes_read]) + .await + .expect("Unable to forward client notification to server"); - let notification = String::from_utf8(buffer[..bytes_read].to_vec()) - .expect("Unable to convert buffer to string"); + let notification = String::from_utf8(buffer[..bytes_read].to_vec()) + .expect("Unable to convert buffer to string"); - if notification.contains("initialize") { - let open_solution_notification = create_open_notification( - ¬ification, - args.solution_path, - args.project_paths, - ); + if notification.contains("initialize") { + let open_solution_notification = + create_open_notification(¬ification, args.solution_path, args.project_paths); - server_stdin - .write_all(open_solution_notification.as_bytes()) - .await - .expect("Unable to send open solution notification to server"); + server_stdin + .write_all(open_solution_notification.as_bytes()) + .await + .expect("Unable to send open solution notification to server"); - break; - } + break; } } io::copy(&mut stdin, &mut server_stdin).await diff --git a/src/server.rs b/src/server.rs index 3c77e83..5407f79 100644 --- a/src/server.rs +++ b/src/server.rs @@ -48,12 +48,17 @@ pub async fn download_server( version: &str, remove_old_server_versions: bool, override_directory: Option, -) { +) -> PathBuf { let dir = override_directory.unwrap_or(cache_dir()); - ensure_server_is_installed(version, remove_old_server_versions, &dir) + let server_path = ensure_server_is_installed(version, remove_old_server_versions, &dir) .await .expect("Unable to install server"); + + match server_path { + ServerPath::Exe(path_buf) => path_buf, + ServerPath::Dll(path_buf) => path_buf, + } } fn cache_dir() -> PathBuf {