mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 23:24:03 +00:00
Auto merge of #12314 - jonas-schievink:proc-macro-load, r=jonas-schievink
minor: simplify
This commit is contained in:
commit
eba26af9f1
4 changed files with 11 additions and 15 deletions
|
@ -88,7 +88,7 @@ fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_crate_graph(project_workspace: ProjectWorkspace) -> CrateGraph {
|
fn to_crate_graph(project_workspace: ProjectWorkspace) -> CrateGraph {
|
||||||
project_workspace.to_crate_graph(&Default::default(), &mut |_, _| Vec::new(), &mut {
|
project_workspace.to_crate_graph(&mut |_, _| Vec::new(), &mut {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
move |_path| {
|
move |_path| {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
|
|
|
@ -389,14 +389,10 @@ impl ProjectWorkspace {
|
||||||
|
|
||||||
pub fn to_crate_graph(
|
pub fn to_crate_graph(
|
||||||
&self,
|
&self,
|
||||||
dummy_replace: &FxHashMap<Box<str>, Box<[Box<str>]>>,
|
load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> Vec<ProcMacro>,
|
||||||
load_proc_macro: &mut dyn FnMut(&AbsPath, &[Box<str>]) -> Vec<ProcMacro>,
|
|
||||||
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
||||||
) -> CrateGraph {
|
) -> CrateGraph {
|
||||||
let _p = profile::span("ProjectWorkspace::to_crate_graph");
|
let _p = profile::span("ProjectWorkspace::to_crate_graph");
|
||||||
let load_proc_macro = &mut |crate_name: &_, path: &_| {
|
|
||||||
load_proc_macro(path, dummy_replace.get(crate_name).map(|it| &**it).unwrap_or_default())
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut crate_graph = match self {
|
let mut crate_graph = match self {
|
||||||
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => project_json_to_crate_graph(
|
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => project_json_to_crate_graph(
|
||||||
|
|
|
@ -66,8 +66,7 @@ pub fn load_workspace(
|
||||||
};
|
};
|
||||||
|
|
||||||
let crate_graph = ws.to_crate_graph(
|
let crate_graph = ws.to_crate_graph(
|
||||||
&Default::default(),
|
&mut |_, path: &AbsPath| load_proc_macro(proc_macro_client.as_ref(), path, &[]),
|
||||||
&mut |path: &AbsPath, _| load_proc_macro(proc_macro_client.as_ref(), 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());
|
||||||
|
|
|
@ -319,8 +319,13 @@ impl GlobalState {
|
||||||
// Create crate graph from all the workspaces
|
// Create crate graph from all the workspaces
|
||||||
let crate_graph = {
|
let crate_graph = {
|
||||||
let proc_macro_client = self.proc_macro_client.as_ref();
|
let proc_macro_client = self.proc_macro_client.as_ref();
|
||||||
let mut load_proc_macro = move |path: &AbsPath, dummy_replace: &_| {
|
let dummy_replacements = self.config.dummy_replacements();
|
||||||
load_proc_macro(proc_macro_client, path, dummy_replace)
|
let mut load_proc_macro = move |crate_name: &str, path: &AbsPath| {
|
||||||
|
load_proc_macro(
|
||||||
|
proc_macro_client,
|
||||||
|
path,
|
||||||
|
dummy_replacements.get(crate_name).map(|v| &**v).unwrap_or_default(),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let vfs = &mut self.vfs.write().0;
|
let vfs = &mut self.vfs.write().0;
|
||||||
|
@ -342,11 +347,7 @@ impl GlobalState {
|
||||||
|
|
||||||
let mut crate_graph = CrateGraph::default();
|
let mut crate_graph = CrateGraph::default();
|
||||||
for ws in self.workspaces.iter() {
|
for ws in self.workspaces.iter() {
|
||||||
crate_graph.extend(ws.to_crate_graph(
|
crate_graph.extend(ws.to_crate_graph(&mut load_proc_macro, &mut load));
|
||||||
self.config.dummy_replacements(),
|
|
||||||
&mut load_proc_macro,
|
|
||||||
&mut load,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
crate_graph
|
crate_graph
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue