Skip to content

Commit f3fdb07

Browse files
authored
Merge pull request #1904 from mo8it/lsp
Fix the sysroot path when it contains whitespaces
2 parents 18d0f34 + 1fe32a7 commit f3fdb07

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/project.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use glob::glob;
22
use serde::{Deserialize, Serialize};
33
use std::env;
44
use std::error::Error;
5-
use std::path::PathBuf;
5+
use std::path::{Path, PathBuf};
66
use std::process::Command;
77

88
/// Contains the structure of resulting rust-project.json file
@@ -79,21 +79,24 @@ impl RustAnalyzerProject {
7979
.output()?
8080
.stdout;
8181

82-
let toolchain = String::from_utf8_lossy(&toolchain);
83-
let mut whitespace_iter = toolchain.split_whitespace();
82+
let toolchain = String::from_utf8(toolchain)?;
83+
let toolchain = toolchain.trim_end();
8484

85-
let toolchain = whitespace_iter.next().unwrap_or(&toolchain);
85+
println!("Determined toolchain: {toolchain}\n");
8686

87-
println!("Determined toolchain: {}\n", &toolchain);
88-
89-
self.sysroot_src = (std::path::Path::new(toolchain)
87+
let Ok(path) = Path::new(toolchain)
9088
.join("lib")
9189
.join("rustlib")
9290
.join("src")
9391
.join("rust")
9492
.join("library")
95-
.to_string_lossy())
96-
.to_string();
93+
.into_os_string()
94+
.into_string()
95+
else {
96+
return Err("The sysroot path is invalid UTF8".into());
97+
};
98+
self.sysroot_src = path;
99+
97100
Ok(())
98101
}
99102
}

0 commit comments

Comments
 (0)