mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
simplify roots
This commit is contained in:
parent
8ada1a2689
commit
9a7db8fa00
5 changed files with 18 additions and 50 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -508,14 +508,6 @@ dependencies = [
|
||||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "owning_ref"
|
name = "owning_ref"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@ -610,9 +602,6 @@ name = "ra_analysis"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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_editor 0.1.0",
|
||||||
"ra_syntax 0.1.0",
|
"ra_syntax 0.1.0",
|
||||||
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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-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-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 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 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 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"
|
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
|
||||||
|
|
|
@ -6,9 +6,6 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
relative-path = "0.4.0"
|
relative-path = "0.4.0"
|
||||||
log = "0.4.2"
|
|
||||||
parking_lot = "0.6.3"
|
|
||||||
once_cell = "0.1.5"
|
|
||||||
rayon = "1.0.2"
|
rayon = "1.0.2"
|
||||||
fst = "0.3.1"
|
fst = "0.3.1"
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
|
|
|
@ -16,7 +16,8 @@ use relative_path::RelativePath;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
descriptors::module::{ModuleTree, Problem},
|
db::SyntaxDatabase,
|
||||||
|
descriptors::module::{ModulesDatabase, ModuleTree, Problem},
|
||||||
descriptors::{FnDescriptor},
|
descriptors::{FnDescriptor},
|
||||||
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
|
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
|
||||||
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
|
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
|
||||||
|
@ -143,10 +144,10 @@ impl AnalysisImpl {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
pub fn file_syntax(&self, file_id: FileId) -> File {
|
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> {
|
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)>> {
|
pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
@ -161,14 +162,14 @@ impl AnalysisImpl {
|
||||||
}
|
}
|
||||||
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
let root = self.root(file_id);
|
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)
|
let res = module_tree.modules_for_file(file_id)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|module_id| {
|
.filter_map(|module_id| {
|
||||||
let link = module_id.parent_link(&module_tree)?;
|
let link = module_id.parent_link(&module_tree)?;
|
||||||
let file_id = link.owner(&module_tree).file_id(&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 decl = link.bind_source(&module_tree, syntax.ast());
|
||||||
|
|
||||||
let sym = FileSymbol {
|
let sym = FileSymbol {
|
||||||
|
@ -182,7 +183,7 @@ impl AnalysisImpl {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
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 crate_graph = &self.data.crate_graph;
|
||||||
let res = module_tree.modules_for_file(file_id)
|
let res = module_tree.modules_for_file(file_id)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -202,8 +203,8 @@ impl AnalysisImpl {
|
||||||
offset: TextUnit,
|
offset: TextUnit,
|
||||||
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
let root = self.root(file_id);
|
let root = self.root(file_id);
|
||||||
let module_tree = root.module_tree()?;
|
let module_tree = root.db().module_tree()?;
|
||||||
let file = root.syntax(file_id);
|
let file = root.db().file_syntax(file_id);
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
||||||
// First try to resolve the symbol locally
|
// 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)> {
|
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> {
|
||||||
let root = self.root(file_id);
|
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 syntax = file.syntax();
|
||||||
|
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
|
@ -285,8 +286,8 @@ impl AnalysisImpl {
|
||||||
|
|
||||||
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
|
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
|
||||||
let root = self.root(file_id);
|
let root = self.root(file_id);
|
||||||
let module_tree = root.module_tree()?;
|
let module_tree = root.db().module_tree()?;
|
||||||
let syntax = root.syntax(file_id);
|
let syntax = root.db().file_syntax(file_id);
|
||||||
|
|
||||||
let mut res = ra_editor::diagnostics(&syntax)
|
let mut res = ra_editor::diagnostics(&syntax)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -376,7 +377,7 @@ impl AnalysisImpl {
|
||||||
offset: TextUnit,
|
offset: TextUnit,
|
||||||
) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
|
) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
|
||||||
let root = self.root(file_id);
|
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 syntax = file.syntax();
|
||||||
|
|
||||||
// Find the calling expression and it's NameRef
|
// Find the calling expression and it's NameRef
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
extern crate parking_lot;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate fst;
|
extern crate fst;
|
||||||
extern crate once_cell;
|
|
||||||
extern crate ra_editor;
|
extern crate ra_editor;
|
||||||
extern crate ra_syntax;
|
extern crate ra_syntax;
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
|
|
|
@ -17,9 +17,7 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) trait SourceRoot {
|
pub(crate) trait SourceRoot {
|
||||||
fn contains(&self, file_id: FileId) -> bool;
|
fn contains(&self, file_id: FileId) -> bool;
|
||||||
fn module_tree(&self) -> Cancelable<Arc<ModuleTree>>;
|
fn db(&self) -> &db::RootDatabase;
|
||||||
fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
|
|
||||||
fn syntax(&self, file_id: FileId) -> File;
|
|
||||||
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>;
|
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,17 +61,11 @@ impl WritableSourceRoot {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourceRoot for WritableSourceRoot {
|
impl SourceRoot for WritableSourceRoot {
|
||||||
fn module_tree(&self) -> Cancelable<Arc<ModuleTree>> {
|
|
||||||
self.db.module_tree()
|
|
||||||
}
|
|
||||||
fn contains(&self, file_id: FileId) -> bool {
|
fn contains(&self, file_id: FileId) -> bool {
|
||||||
self.db.file_set().files.contains(&file_id)
|
self.db.file_set().files.contains(&file_id)
|
||||||
}
|
}
|
||||||
fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
|
fn db(&self) -> &db::RootDatabase {
|
||||||
self.db.file_lines(file_id)
|
&self.db
|
||||||
}
|
|
||||||
fn syntax(&self, file_id: FileId) -> File {
|
|
||||||
self.db.file_syntax(file_id)
|
|
||||||
}
|
}
|
||||||
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
|
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
|
||||||
for &file_id in self.db.file_set().files.iter() {
|
for &file_id in self.db.file_set().files.iter() {
|
||||||
|
@ -114,17 +106,11 @@ impl ReadonlySourceRoot {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourceRoot for ReadonlySourceRoot {
|
impl SourceRoot for ReadonlySourceRoot {
|
||||||
fn module_tree(&self) -> Cancelable<Arc<ModuleTree>> {
|
|
||||||
self.db.module_tree()
|
|
||||||
}
|
|
||||||
fn contains(&self, file_id: FileId) -> bool {
|
fn contains(&self, file_id: FileId) -> bool {
|
||||||
self.db.file_set().files.contains(&file_id)
|
self.db.file_set().files.contains(&file_id)
|
||||||
}
|
}
|
||||||
fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
|
fn db(&self) -> &db::RootDatabase {
|
||||||
self.db.file_lines(file_id)
|
&self.db
|
||||||
}
|
|
||||||
fn syntax(&self, file_id: FileId) -> File {
|
|
||||||
self.db.file_syntax(file_id)
|
|
||||||
}
|
}
|
||||||
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
|
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
|
||||||
acc.push(Arc::clone(&self.symbol_index));
|
acc.push(Arc::clone(&self.symbol_index));
|
||||||
|
|
Loading…
Reference in a new issue