internal: Move proc-macro knowledge out of base-db

This commit is contained in:
Lukas Wirth 2023-12-18 12:09:54 +01:00
parent 21b06c1beb
commit 35620306a6
50 changed files with 255 additions and 186 deletions

View file

@ -7,18 +7,17 @@ use salsa::Durability;
use triomphe::Arc;
use vfs::FileId;
use crate::{CrateGraph, ProcMacros, SourceDatabaseExt, SourceRoot, SourceRootId};
use crate::{CrateGraph, SourceDatabaseExt, SourceRoot, SourceRootId};
/// Encapsulate a bunch of raw `.set` calls on the database.
#[derive(Default)]
pub struct Change {
pub struct FileChange {
pub roots: Option<Vec<SourceRoot>>,
pub files_changed: Vec<(FileId, Option<Arc<str>>)>,
pub crate_graph: Option<CrateGraph>,
pub proc_macros: Option<ProcMacros>,
}
impl fmt::Debug for Change {
impl fmt::Debug for FileChange {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = fmt.debug_struct("Change");
if let Some(roots) = &self.roots {
@ -34,9 +33,9 @@ impl fmt::Debug for Change {
}
}
impl Change {
impl FileChange {
pub fn new() -> Self {
Change::default()
FileChange::default()
}
pub fn set_roots(&mut self, roots: Vec<SourceRoot>) {
@ -51,10 +50,6 @@ impl Change {
self.crate_graph = Some(graph);
}
pub fn set_proc_macros(&mut self, proc_macros: ProcMacros) {
self.proc_macros = Some(proc_macros);
}
pub fn apply(self, db: &mut dyn SourceDatabaseExt) {
let _p = profile::span("RootDatabase::apply_change");
if let Some(roots) = self.roots {
@ -79,9 +74,6 @@ impl Change {
if let Some(crate_graph) = self.crate_graph {
db.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH);
}
if let Some(proc_macros) = self.proc_macros {
db.set_proc_macros_with_durability(Arc::new(proc_macros), Durability::HIGH);
}
}
}