mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Auto merge of #17707 - Veykril:proc-macro-err-cleanup, r=Veykril
feat: Use spans for builtin and declarative macro expansion errors This should generally improve some error reporting for macro expansion errors. Especially for `compile_error!` within proc-macros
This commit is contained in:
commit
a021b85be5
51 changed files with 776 additions and 831 deletions
|
@ -43,7 +43,6 @@ mod parent_module;
|
|||
mod references;
|
||||
mod rename;
|
||||
mod runnables;
|
||||
mod shuffle_crate_graph;
|
||||
mod signature_help;
|
||||
mod ssr;
|
||||
mod static_index;
|
||||
|
@ -202,10 +201,6 @@ impl AnalysisHost {
|
|||
pub fn raw_database_mut(&mut self) -> &mut RootDatabase {
|
||||
&mut self.db
|
||||
}
|
||||
|
||||
pub fn shuffle_crate_graph(&mut self) {
|
||||
shuffle_crate_graph::shuffle_crate_graph(&mut self.db);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AnalysisHost {
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
use hir::{db::ExpandDatabase, ProcMacros};
|
||||
use ide_db::{
|
||||
base_db::{salsa::Durability, CrateGraph, SourceDatabase},
|
||||
FxHashMap, RootDatabase,
|
||||
};
|
||||
use triomphe::Arc;
|
||||
|
||||
// Feature: Shuffle Crate Graph
|
||||
//
|
||||
// Randomizes all crate IDs in the crate graph, for debugging.
|
||||
//
|
||||
// |===
|
||||
// | Editor | Action Name
|
||||
//
|
||||
// | VS Code | **rust-analyzer: Shuffle Crate Graph**
|
||||
// |===
|
||||
pub(crate) fn shuffle_crate_graph(db: &mut RootDatabase) {
|
||||
let crate_graph = db.crate_graph();
|
||||
let proc_macros = db.proc_macros();
|
||||
|
||||
let mut shuffled_ids = crate_graph.iter().collect::<Vec<_>>();
|
||||
|
||||
let mut rng = oorandom::Rand32::new(stdx::rand::seed());
|
||||
stdx::rand::shuffle(&mut shuffled_ids, |i| rng.rand_range(0..i as u32) as usize);
|
||||
|
||||
let mut new_graph = CrateGraph::default();
|
||||
let mut new_proc_macros = ProcMacros::default();
|
||||
|
||||
let mut map = FxHashMap::default();
|
||||
for old_id in shuffled_ids.iter().copied() {
|
||||
let data = &crate_graph[old_id];
|
||||
let new_id = new_graph.add_crate_root(
|
||||
data.root_file_id,
|
||||
data.edition,
|
||||
data.display_name.clone(),
|
||||
data.version.clone(),
|
||||
data.cfg_options.clone(),
|
||||
data.potential_cfg_options.clone(),
|
||||
data.env.clone(),
|
||||
data.is_proc_macro,
|
||||
data.origin.clone(),
|
||||
);
|
||||
new_proc_macros.insert(new_id, proc_macros[&old_id].clone());
|
||||
map.insert(old_id, new_id);
|
||||
}
|
||||
|
||||
for old_id in shuffled_ids.iter().copied() {
|
||||
let data = &crate_graph[old_id];
|
||||
for dep in &data.dependencies {
|
||||
let mut new_dep = dep.clone();
|
||||
new_dep.crate_id = map[&dep.crate_id];
|
||||
new_graph.add_dep(map[&old_id], new_dep).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
db.set_crate_graph_with_durability(Arc::new(new_graph), Durability::HIGH);
|
||||
db.set_proc_macros_with_durability(Arc::new(new_proc_macros), Durability::HIGH);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue