Move input to top-level

This commit is contained in:
Aleksey Kladov 2018-10-25 17:52:50 +03:00
parent 5ef3fda5e1
commit d190019571
9 changed files with 67 additions and 62 deletions

6
Cargo.lock generated
View file

@ -608,7 +608,7 @@ dependencies = [
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0",
]
@ -834,7 +834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "salsa"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1350,7 +1350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fc085b9e4a2cf422e798387d0dc1091c6dae97411b2b177755950db9a26dace"
"checksum salsa 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fe802c02c7b0074b0b4794442d73e3c7d071967300a98bb0f5dfc25e9f1ef"
"checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"

View file

@ -11,7 +11,7 @@ rayon = "1.0.2"
fst = "0.3.1"
ra_syntax = { path = "../ra_syntax" }
ra_editor = { path = "../ra_editor" }
salsa = "0.6.1"
salsa = "0.6.2"
rustc-hash = "1.0"
[dev-dependencies]

View file

@ -6,7 +6,8 @@ use ra_syntax::{
use crate::{
FileId, Cancelable,
db::{self, SyntaxDatabase, input::FilesDatabase},
input::FilesDatabase,
db::{self, SyntaxDatabase},
descriptors::module::{ModulesDatabase, ModuleTree, ModuleId},
};

View file

@ -1,5 +1,3 @@
pub(crate) mod input;
use std::{
sync::Arc,
};
@ -51,13 +49,13 @@ impl Clone for RootDatabase {
salsa::database_storage! {
pub(crate) struct RootDatabaseStorage for RootDatabase {
impl input::FilesDatabase {
fn file_text() for input::FileTextQuery;
fn file_source_root() for input::FileSourceRootQuery;
fn source_root() for input::SourceRootQuery;
fn libraries() for input::LibrarieseQuery;
fn library_symbols() for input::LibrarySymbolsQuery;
fn crate_graph() for input::CrateGraphQuery;
impl crate::input::FilesDatabase {
fn file_text() for crate::input::FileTextQuery;
fn file_source_root() for crate::input::FileSourceRootQuery;
fn source_root() for crate::input::SourceRootQuery;
fn libraries() for crate::input::LibrarieseQuery;
fn library_symbols() for crate::input::LibrarySymbolsQuery;
fn crate_graph() for crate::input::CrateGraphQuery;
}
impl SyntaxDatabase {
fn file_syntax() for FileSyntaxQuery;
@ -72,7 +70,7 @@ salsa::database_storage! {
}
salsa::query_group! {
pub(crate) trait SyntaxDatabase: input::FilesDatabase {
pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase {
fn file_syntax(file_id: FileId) -> File {
type FileSyntaxQuery;
}

View file

@ -8,8 +8,8 @@ use ra_syntax::{
};
use crate::{
FileId, Cancelable, FileResolverImp,
db::{self, input::{SourceRoot, SourceRootId}},
FileId, Cancelable, FileResolverImp, db,
input::{SourceRoot, SourceRootId},
};
use super::{

View file

@ -7,7 +7,8 @@ use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode};
use crate::{
FileId, Cancelable,
db::{SyntaxDatabase, input::SourceRootId},
db::SyntaxDatabase,
input::SourceRootId,
};
salsa::query_group! {

View file

@ -18,8 +18,9 @@ use crate::{
AnalysisChange,
db::{
self, SyntaxDatabase,
input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE}
},
input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE},
descriptors::module::{ModulesDatabase, ModuleTree, Problem},
descriptors::{FnDescriptor},
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
@ -102,7 +103,7 @@ impl AnalysisHostImpl {
for (file_id, text) in change.files_changed {
self.db
.query(db::input::FileTextQuery)
.query(crate::input::FileTextQuery)
.set(file_id, Arc::new(text))
}
if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
@ -111,22 +112,22 @@ impl AnalysisHostImpl {
let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
for (file_id, text) in change.files_added {
self.db
.query(db::input::FileTextQuery)
.query(crate::input::FileTextQuery)
.set(file_id, Arc::new(text));
self.db
.query(db::input::FileSourceRootQuery)
.set(file_id, db::input::WORKSPACE);
.query(crate::input::FileSourceRootQuery)
.set(file_id, crate::input::WORKSPACE);
source_root.files.insert(file_id);
}
for file_id in change.files_removed {
self.db
.query(db::input::FileTextQuery)
.query(crate::input::FileTextQuery)
.set(file_id, Arc::new(String::new()));
source_root.files.remove(&file_id);
}
source_root.file_resolver = file_resolver;
self.db
.query(db::input::SourceRootQuery)
.query(crate::input::SourceRootQuery)
.set(WORKSPACE, Arc::new(source_root))
}
if !change.libraries_added.is_empty() {
@ -138,10 +139,10 @@ impl AnalysisHostImpl {
for (file_id, text) in library.files {
files.insert(file_id);
self.db
.query(db::input::FileSourceRootQuery)
.query(crate::input::FileSourceRootQuery)
.set_constant(file_id, source_root_id);
self.db
.query(db::input::FileTextQuery)
.query(crate::input::FileTextQuery)
.set_constant(file_id, Arc::new(text));
}
let source_root = SourceRoot {
@ -149,18 +150,18 @@ impl AnalysisHostImpl {
file_resolver: library.file_resolver,
};
self.db
.query(db::input::SourceRootQuery)
.query(crate::input::SourceRootQuery)
.set(source_root_id, Arc::new(source_root));
self.db
.query(db::input::LibrarySymbolsQuery)
.query(crate::input::LibrarySymbolsQuery)
.set(source_root_id, Arc::new(library.symbol_index));
}
self.db
.query(db::input::LibrarieseQuery)
.query(crate::input::LibrarieseQuery)
.set((), Arc::new(libraries));
}
if let Some(crate_graph) = change.crate_graph {
self.db.query(db::input::CrateGraphQuery)
self.db.query(crate::input::CrateGraphQuery)
.set((), Arc::new(crate_graph))
}
}

View file

@ -1,11 +1,42 @@
use std::{
sync::Arc,
fmt,
};
use salsa;
use rustc_hash::FxHashSet;
use relative_path::RelativePath;
use rustc_hash::FxHashMap;
use crate::{FileId, FileResolverImp, CrateGraph, symbol_index::SymbolIndex};
use crate::{symbol_index::SymbolIndex, FileResolverImp};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FileId(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CrateId(pub u32);
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct CrateGraph {
pub(crate) crate_roots: FxHashMap<CrateId, FileId>,
}
impl CrateGraph {
pub fn new() -> CrateGraph {
CrateGraph::default()
}
pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{
let crate_id = CrateId(self.crate_roots.len() as u32);
let prev = self.crate_roots.insert(crate_id, file_id);
assert!(prev.is_none());
crate_id
}
}
pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
fn file_stem(&self, file_id: FileId) -> String;
fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
}
salsa::query_group! {
pub(crate) trait FilesDatabase: salsa::Database {

View file

@ -6,6 +6,7 @@ extern crate relative_path;
extern crate rustc_hash;
extern crate salsa;
mod input;
mod db;
mod descriptors;
mod imp;
@ -17,9 +18,8 @@ use std::{
sync::Arc,
};
use rustc_hash::FxHashMap;
use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
use relative_path::{RelativePath, RelativePathBuf};
use relative_path::RelativePathBuf;
use rayon::prelude::*;
use crate::{
@ -29,6 +29,7 @@ use crate::{
pub use crate::{
descriptors::FnDescriptor,
input::{FileId, FileResolver, CrateGraph, CrateId}
};
pub use ra_editor::{
CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable,
@ -49,34 +50,6 @@ impl std::fmt::Display for Canceled {
impl std::error::Error for Canceled {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FileId(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CrateId(pub u32);
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct CrateGraph {
crate_roots: FxHashMap<CrateId, FileId>,
}
impl CrateGraph {
pub fn new() -> CrateGraph {
CrateGraph::default()
}
pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{
let crate_id = CrateId(self.crate_roots.len() as u32);
let prev = self.crate_roots.insert(crate_id, file_id);
assert!(prev.is_none());
crate_id
}
}
pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
fn file_stem(&self, file_id: FileId) -> String;
fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
}
#[derive(Default)]
pub struct AnalysisChange {
files_added: Vec<(FileId, String)>,