Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
64 changes: 26 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -34,10 +34,6 @@ struct Args {
/// Override project(s) (.csproj) path(s). Absolute path. Solution path takes precedence
#[arg(short, long)]
project_paths: Option<Vec<String>>,

/// Disable sending any "open" commands.
#[arg(short, long, default_value_t = false)]
no_open: bool,
}

#[tokio::main]
Expand All @@ -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;
}

Expand All @@ -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(
&notification,
args.solution_path,
args.project_paths,
);
if notification.contains("initialize") {
let open_solution_notification =
create_open_notification(&notification, 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
Expand Down
9 changes: 7 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ pub async fn download_server(
version: &str,
remove_old_server_versions: bool,
override_directory: Option<PathBuf>,
) {
) -> 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 {
Expand Down
Loading