simplify roots

This commit is contained in:
Aleksey Kladov 2018-10-24 17:25:10 +03:00
parent 8ada1a2689
commit 9a7db8fa00
5 changed files with 18 additions and 50 deletions

12
Cargo.lock generated
View file

@ -508,14 +508,6 @@ dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "once_cell"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "owning_ref"
version = "0.3.3"
@ -610,9 +602,6 @@ name = "ra_analysis"
version = "0.1.0"
dependencies = [
"fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ra_editor 0.1.0",
"ra_syntax 0.1.0",
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1330,7 +1319,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
"checksum once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d7ce3535d54560c937c1652ba4a0da66bfc63e0f8e07bed127483afb6e5ee925"
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5"
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"

View file

@ -6,9 +6,6 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
[dependencies]
relative-path = "0.4.0"
log = "0.4.2"
parking_lot = "0.6.3"
once_cell = "0.1.5"
rayon = "1.0.2"
fst = "0.3.1"
ra_syntax = { path = "../ra_syntax" }

View file

@ -16,7 +16,8 @@ use relative_path::RelativePath;
use rustc_hash::FxHashSet;
use crate::{
descriptors::module::{ModuleTree, Problem},
db::SyntaxDatabase,
descriptors::module::{ModulesDatabase, ModuleTree, Problem},
descriptors::{FnDescriptor},
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
@ -143,10 +144,10 @@ impl AnalysisImpl {
.unwrap()
}
pub fn file_syntax(&self, file_id: FileId) -> File {
self.root(file_id).syntax(file_id)
self.root(file_id).db().file_syntax(file_id)
}
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
self.root(file_id).lines(file_id)
self.root(file_id).db().file_lines(file_id)
}
pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
let mut buf = Vec::new();
@ -161,14 +162,14 @@ impl AnalysisImpl {
}
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
let root = self.root(file_id);
let module_tree = root.module_tree()?;
let module_tree = root.db().module_tree()?;
let res = module_tree.modules_for_file(file_id)
.into_iter()
.filter_map(|module_id| {
let link = module_id.parent_link(&module_tree)?;
let file_id = link.owner(&module_tree).file_id(&module_tree);
let syntax = root.syntax(file_id);
let syntax = root.db().file_syntax(file_id);
let decl = link.bind_source(&module_tree, syntax.ast());
let sym = FileSymbol {
@ -182,7 +183,7 @@ impl AnalysisImpl {
Ok(res)
}
pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
let module_tree = self.root(file_id).module_tree()?;
let module_tree = self.root(file_id).db().module_tree()?;
let crate_graph = &self.data.crate_graph;
let res = module_tree.modules_for_file(file_id)
.into_iter()
@ -202,8 +203,8 @@ impl AnalysisImpl {
offset: TextUnit,
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
let root = self.root(file_id);
let module_tree = root.module_tree()?;
let file = root.syntax(file_id);
let module_tree = root.db().module_tree()?;
let file = root.db().file_syntax(file_id);
let syntax = file.syntax();
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
// First try to resolve the symbol locally
@ -253,7 +254,7 @@ impl AnalysisImpl {
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> {
let root = self.root(file_id);
let file = root.syntax(file_id);
let file = root.db().file_syntax(file_id);
let syntax = file.syntax();
let mut ret = vec![];
@ -285,8 +286,8 @@ impl AnalysisImpl {
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
let root = self.root(file_id);
let module_tree = root.module_tree()?;
let syntax = root.syntax(file_id);
let module_tree = root.db().module_tree()?;
let syntax = root.db().file_syntax(file_id);
let mut res = ra_editor::diagnostics(&syntax)
.into_iter()
@ -376,7 +377,7 @@ impl AnalysisImpl {
offset: TextUnit,
) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
let root = self.root(file_id);
let file = root.syntax(file_id);
let file = root.db().file_syntax(file_id);
let syntax = file.syntax();
// Find the calling expression and it's NameRef

View file

@ -1,8 +1,4 @@
extern crate parking_lot;
#[macro_use]
extern crate log;
extern crate fst;
extern crate once_cell;
extern crate ra_editor;
extern crate ra_syntax;
extern crate rayon;

View file

@ -17,9 +17,7 @@ use crate::{
pub(crate) trait SourceRoot {
fn contains(&self, file_id: FileId) -> bool;
fn module_tree(&self) -> Cancelable<Arc<ModuleTree>>;
fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
fn syntax(&self, file_id: FileId) -> File;
fn db(&self) -> &db::RootDatabase;
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>;
}
@ -63,17 +61,11 @@ impl WritableSourceRoot {
}
impl SourceRoot for WritableSourceRoot {
fn module_tree(&self) -> Cancelable<Arc<ModuleTree>> {
self.db.module_tree()
}
fn contains(&self, file_id: FileId) -> bool {
self.db.file_set().files.contains(&file_id)
}
fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
self.db.file_lines(file_id)
}
fn syntax(&self, file_id: FileId) -> File {
self.db.file_syntax(file_id)
fn db(&self) -> &db::RootDatabase {
&self.db
}
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
for &file_id in self.db.file_set().files.iter() {
@ -114,17 +106,11 @@ impl ReadonlySourceRoot {
}
impl SourceRoot for ReadonlySourceRoot {
fn module_tree(&self) -> Cancelable<Arc<ModuleTree>> {
self.db.module_tree()
}
fn contains(&self, file_id: FileId) -> bool {
self.db.file_set().files.contains(&file_id)
}
fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
self.db.file_lines(file_id)
}
fn syntax(&self, file_id: FileId) -> File {
self.db.file_syntax(file_id)
fn db(&self) -> &db::RootDatabase {
&self.db
}
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
acc.push(Arc::clone(&self.symbol_index));