Remove dummy ProcMacroClient in favor of Option

This commit is contained in:
Jonas Schievink
2020-12-07 17:16:50 +01:00
parent fb21a215be
commit 2b2318e695
5 changed files with 59 additions and 71 deletions

View File

@@ -33,12 +33,12 @@ pub fn load_cargo(
let proc_macro_client = if with_proc_macro {
let path = std::env::current_exe()?;
ProcMacroClient::extern_process(path, &["proc-macro"]).unwrap()
Some(ProcMacroClient::extern_process(path, &["proc-macro"]).unwrap())
} else {
ProcMacroClient::dummy()
None
};
let crate_graph = ws.to_crate_graph(None, &proc_macro_client, &mut |path: &AbsPath| {
let crate_graph = ws.to_crate_graph(None, proc_macro_client.as_ref(), &mut |path: &AbsPath| {
let contents = loader.load_sync(path);
let path = vfs::VfsPath::from(path.to_path_buf());
vfs.set_file_contents(path.clone(), contents);

View File

@@ -75,7 +75,7 @@ pub(crate) struct GlobalState {
pub(crate) shutdown_requested: bool,
pub(crate) status: Status,
pub(crate) source_root_config: SourceRootConfig,
pub(crate) proc_macro_client: ProcMacroClient,
pub(crate) proc_macro_client: Option<ProcMacroClient>,
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
latest_requests: Arc<RwLock<LatestRequests>>,
}
@@ -127,7 +127,7 @@ impl GlobalState {
shutdown_requested: false,
status: Status::default(),
source_root_config: SourceRootConfig::default(),
proc_macro_client: ProcMacroClient::dummy(),
proc_macro_client: None,
workspaces: Arc::new(Vec::new()),
latest_requests: Default::default(),
}

View File

@@ -171,16 +171,16 @@ impl GlobalState {
let project_folders = ProjectFolders::new(&workspaces);
self.proc_macro_client = match &self.config.proc_macro_srv {
None => ProcMacroClient::dummy(),
None => None,
Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) {
Ok(it) => it,
Ok(it) => Some(it),
Err(err) => {
log::error!(
"Failed to run proc_macro_srv from path {}, error: {:?}",
path.display(),
err
);
ProcMacroClient::dummy()
None
}
},
};
@@ -212,7 +212,7 @@ impl GlobalState {
for ws in workspaces.iter() {
crate_graph.extend(ws.to_crate_graph(
self.config.cargo.target.as_deref(),
&self.proc_macro_client,
self.proc_macro_client.as_ref(),
&mut load,
));
}