mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Add SourceRoot::is_library, in preparation for salsa's durability
This commit is contained in:
parent
7d79be3280
commit
8109ebb101
2 changed files with 16 additions and 1 deletions
|
@ -31,9 +31,23 @@ pub struct SourceRootId(pub u32);
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug, PartialEq, Eq)]
|
#[derive(Default, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct SourceRoot {
|
pub struct SourceRoot {
|
||||||
|
/// Sysroot or crates.io library.
|
||||||
|
///
|
||||||
|
/// Libraries are considered mostly immutable, this assumption is used to
|
||||||
|
/// optimize salsa's query structure
|
||||||
|
pub is_library: bool,
|
||||||
pub files: FxHashMap<RelativePathBuf, FileId>,
|
pub files: FxHashMap<RelativePathBuf, FileId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SourceRoot {
|
||||||
|
pub fn new() -> SourceRoot {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
pub fn new_library() -> SourceRoot {
|
||||||
|
SourceRoot { is_library: true, ..SourceRoot::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// `CrateGraph` is a bit of information which turns a set of text files into a
|
/// `CrateGraph` is a bit of information which turns a set of text files into a
|
||||||
/// number of Rust crates. Each crate is defined by the `FileId` of its root module,
|
/// number of Rust crates. Each crate is defined by the `FileId` of its root module,
|
||||||
/// the set of cfg flags (not yet implemented) and the set of dependencies. Note
|
/// the set of cfg flags (not yet implemented) and the set of dependencies. Note
|
||||||
|
|
|
@ -163,7 +163,8 @@ impl RootDatabase {
|
||||||
if !change.new_roots.is_empty() {
|
if !change.new_roots.is_empty() {
|
||||||
let mut local_roots = Vec::clone(&self.local_roots());
|
let mut local_roots = Vec::clone(&self.local_roots());
|
||||||
for (root_id, is_local) in change.new_roots {
|
for (root_id, is_local) in change.new_roots {
|
||||||
self.set_source_root(root_id, Default::default());
|
let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() };
|
||||||
|
self.set_source_root(root_id, Arc::new(root));
|
||||||
if is_local {
|
if is_local {
|
||||||
local_roots.push(root_id);
|
local_roots.push(root_id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue