Auto merge of #14671 - Veykril:proc-macro-srv-conf, r=Veykril

fix: Fix proc-macro-srv path config not working
This commit is contained in:
bors 2023-04-28 19:18:14 +00:00
commit 3ad835faa9
2 changed files with 46 additions and 6 deletions

View File

@ -1102,12 +1102,8 @@ pub fn lru_query_capacities(&self) -> Option<&FxHashMap<Box<str>, usize>> {
} }
pub fn proc_macro_srv(&self) -> Option<AbsPathBuf> { pub fn proc_macro_srv(&self) -> Option<AbsPathBuf> {
self.data let path = self.data.procMacro_server.clone()?;
.procMacro_server Some(AbsPathBuf::try_from(path).unwrap_or_else(|path| self.root_path.join(&path)))
.clone()
.map(AbsPathBuf::try_from)?
.ok()
.map(|path| self.root_path.join(path))
} }
pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> { pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> {
@ -2424,4 +2420,43 @@ fn generate_config_documentation() {
fn remove_ws(text: &str) -> String { fn remove_ws(text: &str) -> String {
text.replace(char::is_whitespace, "") text.replace(char::is_whitespace, "")
} }
#[test]
fn proc_macro_srv_null() {
let mut config =
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
config
.update(serde_json::json!({
"procMacro_server": null,
}))
.unwrap();
assert_eq!(config.proc_macro_srv(), None);
}
#[test]
fn proc_macro_srv_abs() {
let mut config =
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
config
.update(serde_json::json!({
"procMacro": {"server": project_root().display().to_string()}
}))
.unwrap();
assert_eq!(config.proc_macro_srv(), Some(AbsPathBuf::try_from(project_root()).unwrap()));
}
#[test]
fn proc_macro_srv_rel() {
let mut config =
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
config
.update(serde_json::json!({
"procMacro": {"server": "./server"}
}))
.unwrap();
assert_eq!(
config.proc_macro_srv(),
Some(AbsPathBuf::try_from(project_root().join("./server")).unwrap())
);
}
} }

View File

@ -426,6 +426,11 @@ pub(crate) fn switch_workspaces(&mut self, cause: Cause) {
tracing::info!("Using proc-macro server at {}", path.display(),); tracing::info!("Using proc-macro server at {}", path.display(),);
ProcMacroServer::spawn(path.clone()).map_err(|err| { ProcMacroServer::spawn(path.clone()).map_err(|err| {
tracing::error!(
"Failed to run proc-macro server from path {}, error: {:?}",
path.display(),
err
);
anyhow::anyhow!( anyhow::anyhow!(
"Failed to run proc-macro server from path {}, error: {:?}", "Failed to run proc-macro server from path {}, error: {:?}",
path.display(), path.display(),