diff options
| author | liv <mokou@fastmail.com> | 2024-03-18 18:43:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-18 18:43:07 +0100 |
| commit | f3fdb075077d5ea3bb5efcbbc0e222d29480bca5 (patch) | |
| tree | b332d3bc1a348b25a4b636be66e45d8c2d981338 | |
| parent | 18d0f3411fc9ae9536e49e9cc33a349f1caa7414 (diff) | |
| parent | 1fe32a7ff2250ae893fdd54b394e6521d32dd024 (diff) | |
Merge pull request #1904 from mo8it/lsp
Fix the sysroot path when it contains whitespaces
| -rw-r--r-- | src/project.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/project.rs b/src/project.rs index bcbd7ad..00fc304 100644 --- a/src/project.rs +++ b/src/project.rs @@ -2,7 +2,7 @@ use glob::glob; use serde::{Deserialize, Serialize}; use std::env; use std::error::Error; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; /// Contains the structure of resulting rust-project.json file @@ -79,21 +79,24 @@ impl RustAnalyzerProject { .output()? .stdout; - let toolchain = String::from_utf8_lossy(&toolchain); - let mut whitespace_iter = toolchain.split_whitespace(); + let toolchain = String::from_utf8(toolchain)?; + let toolchain = toolchain.trim_end(); - let toolchain = whitespace_iter.next().unwrap_or(&toolchain); + println!("Determined toolchain: {toolchain}\n"); - println!("Determined toolchain: {}\n", &toolchain); - - self.sysroot_src = (std::path::Path::new(toolchain) + let Ok(path) = Path::new(toolchain) .join("lib") .join("rustlib") .join("src") .join("rust") .join("library") - .to_string_lossy()) - .to_string(); + .into_os_string() + .into_string() + else { + return Err("The sysroot path is invalid UTF8".into()); + }; + self.sysroot_src = path; + Ok(()) } } |
