Auto merge of #12881 - Veykril:proc-srv, r=Veykril

fix: Fix server panicking on project loading when proc-macros are disabled

Fixes https://github.com/rust-lang/rust-analyzer/issues/12879
This commit is contained in:
bors 2022-07-26 14:31:26 +00:00
commit 7a30f62ecf
2 changed files with 8 additions and 3 deletions

View file

@ -66,7 +66,9 @@ pub fn load_workspace(
}; };
let crate_graph = ws.to_crate_graph( let crate_graph = ws.to_crate_graph(
&mut |_, path: &AbsPath| load_proc_macro(proc_macro_client.as_ref(), path, &[]), &mut |_, path: &AbsPath| {
load_proc_macro(proc_macro_client.as_ref().map_err(|e| &**e), path, &[])
},
&mut |path: &AbsPath| { &mut |path: &AbsPath| {
let contents = loader.load_sync(path); let contents = loader.load_sync(path);
let path = vfs::VfsPath::from(path.to_path_buf()); let path = vfs::VfsPath::from(path.to_path_buf());

View file

@ -390,7 +390,10 @@ impl GlobalState {
let mut crate_graph = CrateGraph::default(); let mut crate_graph = CrateGraph::default();
for (idx, ws) in self.workspaces.iter().enumerate() { for (idx, ws) in self.workspaces.iter().enumerate() {
let proc_macro_client = self.proc_macro_clients[idx].as_ref(); let proc_macro_client = match self.proc_macro_clients.get(idx) {
Some(res) => res.as_ref().map_err(|e| &**e),
None => Err("Proc macros are disabled"),
};
let mut load_proc_macro = move |crate_name: &str, path: &AbsPath| { let mut load_proc_macro = move |crate_name: &str, path: &AbsPath| {
load_proc_macro( load_proc_macro(
proc_macro_client, proc_macro_client,
@ -574,7 +577,7 @@ impl SourceRootConfig {
/// Load the proc-macros for the given lib path, replacing all expanders whose names are in `dummy_replace` /// Load the proc-macros for the given lib path, replacing all expanders whose names are in `dummy_replace`
/// with an identity dummy expander. /// with an identity dummy expander.
pub(crate) fn load_proc_macro( pub(crate) fn load_proc_macro(
server: Result<&ProcMacroServer, &String>, server: Result<&ProcMacroServer, &str>,
path: &AbsPath, path: &AbsPath,
dummy_replace: &[Box<str>], dummy_replace: &[Box<str>],
) -> ProcMacroLoadResult { ) -> ProcMacroLoadResult {