Skip to content

Commit

Permalink
Move project files to XDG-compliant location (#28)
Browse files Browse the repository at this point in the history
Also refactor path handling a bit to be immutable.
  • Loading branch information
milhnl authored Sep 29, 2024
1 parent 1fe1142 commit f07e0a5
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 45 deletions.
126 changes: 105 additions & 21 deletions 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
Expand Up @@ -8,9 +8,9 @@ description = "A tool that simplifies installation and running C# language serve
[dependencies]
anyhow = "1.0.86"
clap = { version = "4.5", features = ["derive"] }
directories = "5.0.1"
fs_extra = "1.3.0"
futures = "0.3.30"
home = "0.5.9"
rust_search = "2.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
33 changes: 15 additions & 18 deletions src/download_roslyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ use tokio::process::Command;
pub async fn ensure_roslyn_is_installed(
version: &str,
remove_old_server_versions: bool,
cache_dir: &PathBuf,
) -> Result<PathBuf> {
let mut roslyn_server_dir = home::home_dir().expect("Unable to find home directory");
roslyn_server_dir.push(".roslyn");
roslyn_server_dir.push("server");
let roslyn_server_dir = cache_dir.join("server");

let mut dll_version_dir = roslyn_server_dir.clone();
dll_version_dir.push(version);
let dll_version_dir = roslyn_server_dir.join(version);

let mut dll_path = dll_version_dir.clone();
dll_path.push("Microsoft.CodeAnalysis.LanguageServer.dll");
let dll_path = dll_version_dir.join("Microsoft.CodeAnalysis.LanguageServer.dll");

if std::path::Path::new(&dll_path).exists() {
return Ok(dll_path);
Expand All @@ -28,28 +25,28 @@ pub async fn ensure_roslyn_is_installed(
fs_extra::dir::create_all(&roslyn_server_dir, remove_old_server_versions)?;
fs_extra::dir::create_all(&dll_version_dir, true)?;

let mut temp_build_dir = temp_dir();
temp_build_dir.push("roslyn");
fs_extra::dir::create(&temp_build_dir, true)?;
let temp_build_root = temp_dir().join("roslyn");
fs_extra::dir::create(&temp_build_root, true)?;

create_csharp_project(&temp_build_dir)?;
create_csharp_project(&temp_build_root)?;

Command::new("dotnet")
.arg("add")
.arg("package")
.arg("Microsoft.CodeAnalysis.LanguageServer.neutral")
.arg("-v")
.arg(version)
.current_dir(fs::canonicalize(temp_build_dir.clone())?)
.current_dir(fs::canonicalize(temp_build_root.clone())?)
.output()
.await?;

temp_build_dir.push("out");
temp_build_dir.push("microsoft.codeanalysis.languageserver.neutral");
temp_build_dir.push(version);
temp_build_dir.push("content");
temp_build_dir.push("LanguageServer");
temp_build_dir.push("neutral");
let temp_build_dir = temp_build_root
.join("out")
.join("microsoft.codeanalysis.languageserver.neutral")
.join(version)
.join("content")
.join("LanguageServer")
.join("neutral");

let copy_options = fs_extra::dir::CopyOptions::default()
.overwrite(true)
Expand Down
13 changes: 8 additions & 5 deletions src/roslyn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::process::Stdio;

use anyhow::{bail, Context, Result};
use home::home_dir;
use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
use tokio::{
io::{AsyncBufReadExt, BufReader},
Expand Down Expand Up @@ -33,13 +33,16 @@ async fn parse_roslyn_response(reader: BufReader<ChildStdout>) -> Result<RoslynR
}

pub async fn start_roslyn(version: &str, remove_old_server_versions: bool) -> Box<dyn PipeStream> {
let mut log_dir = home_dir().expect("Unable to find home directory");
log_dir.push(".roslyn");
log_dir.push("logs");
let cache_dir = ProjectDirs::from("com", "github", "roslyn-language-server")
.expect("Unable to find cache directory")
.cache_dir()
.to_path_buf();

let log_dir = cache_dir.join("log");

let mut process: Child;

let roslyn_dll = ensure_roslyn_is_installed(version, remove_old_server_versions)
let roslyn_dll = ensure_roslyn_is_installed(version, remove_old_server_versions, &cache_dir)
.await
.expect("Unable to install Roslyn");

Expand Down

0 comments on commit f07e0a5

Please sign in to comment.