664: rename FilesDatabase -> SourceDatabase r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-01-26 08:20:53 +00:00
commit ac757e114e
17 changed files with 45 additions and 56 deletions

View file

@ -20,7 +20,7 @@ pub use crate::{
loc2id::LocationIntener,
};
pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
pub trait CheckCanceled: salsa::Database + panic::RefUnwindSafe {
/// Aborts current query if there are pending changes.
///
/// rust-analyzer needs to be able to answer semantic questions about the
@ -63,11 +63,15 @@ pub struct FileRange {
pub range: TextRange,
}
#[salsa::query_group(FilesDatabaseStorage)]
pub trait FilesDatabase: salsa::Database {
/// Database which stores all significant input facts: source code and project
/// model. Everything else in rust-analyzer is derived from these queries.
#[salsa::query_group(SourceDatabaseStorage)]
pub trait SourceDatabase: salsa::Database + CheckCanceled {
/// Text of the file.
#[salsa::input]
fn file_text(&self, file_id: FileId) -> Arc<String>;
// Parses the file into the syntax tree.
fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
/// Path to a file, relative to the root of its source root.
#[salsa::input]
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
@ -78,20 +82,12 @@ pub trait FilesDatabase: salsa::Database {
#[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
#[salsa::input]
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
}
fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
let root = db.source_root(id);
let graph = db.crate_graph();
let res = root
@ -102,12 +98,7 @@ fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<Crat
Arc::new(res)
}
#[salsa::query_group(SyntaxDatabaseStorage)]
pub trait SyntaxDatabase: FilesDatabase + BaseDatabase {
fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
}
fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {
fn source_file(db: &impl SourceDatabase, file_id: FileId) -> TreeArc<SourceFile> {
let text = db.file_text(file_id);
SourceFile::parse(&*text)
}

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
use ra_db::{SyntaxDatabase, CrateId, salsa};
use ra_db::{SourceDatabase, CrateId, salsa};
use crate::{
MacroCallId, HirFileId,
@ -19,7 +19,7 @@ use crate::{
};
#[salsa::query_group(HirDatabaseStorage)]
pub trait HirDatabase: SyntaxDatabase + AsRef<HirInterner> {
pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> {
#[salsa::invoke(HirFileId::hir_source_file)]
fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>;

View file

@ -2,7 +2,7 @@ use std::{sync::Arc, panic};
use parking_lot::Mutex;
use ra_db::{
BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase, salsa,
CheckCanceled, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa,
};
use relative_path::RelativePathBuf;
use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
@ -11,11 +11,7 @@ use crate::{db, HirInterner};
pub const WORKSPACE: SourceRootId = SourceRootId(0);
#[salsa::database(
ra_db::FilesDatabaseStorage,
ra_db::SyntaxDatabaseStorage,
db::HirDatabaseStorage
)]
#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage)]
#[derive(Debug)]
pub(crate) struct MockDatabase {
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
@ -144,8 +140,6 @@ impl Default for MockDatabase {
file_counter: 0,
};
db.set_crate_graph(Default::default());
db.set_local_roots(Default::default());
db.set_library_roots(Default::default());
db
}
}
@ -161,7 +155,7 @@ impl salsa::ParallelDatabase for MockDatabase {
}
}
impl BaseDatabase for MockDatabase {}
impl CheckCanceled for MockDatabase {}
impl AsRef<HirInterner> for MockDatabase {
fn as_ref(&self) -> &HirInterner {

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use ra_db::{CrateGraph, SourceRootId, FilesDatabase};
use ra_db::{CrateGraph, SourceRootId, SourceDatabase};
use relative_path::RelativePath;
use test_utils::{assert_eq_text, covers};

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use std::fmt::Write;
use ra_db::{SyntaxDatabase, salsa::Database};
use ra_db::{SourceDatabase, salsa::Database};
use ra_syntax::ast::{self, AstNode};
use crate::{

View file

@ -1,4 +1,4 @@
use ra_db::SyntaxDatabase;
use ra_db::SourceDatabase;
use ra_syntax::{
AstNode, SyntaxNode, TextUnit, TextRange,
SyntaxKind::FN_DEF,

View file

@ -9,7 +9,7 @@ mod complete_path;
mod complete_scope;
mod complete_postfix;
use ra_db::SyntaxDatabase;
use ra_db::SourceDatabase;
use crate::{
db,

View file

@ -1,15 +1,14 @@
use std::sync::Arc;
use ra_db::{
BaseDatabase, FileId, Canceled,
salsa::{self, Database},
CheckCanceled, FileId, Canceled, SourceDatabase,
salsa,
};
use crate::{symbol_index, LineIndex};
use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
#[salsa::database(
ra_db::FilesDatabaseStorage,
ra_db::SyntaxDatabaseStorage,
ra_db::SourceDatabaseStorage,
LineIndexDatabaseStorage,
symbol_index::SymbolsDatabaseStorage,
hir::db::HirDatabaseStorage
@ -35,12 +34,9 @@ impl Default for RootDatabase {
runtime: salsa::Runtime::default(),
interner: Default::default(),
};
db.query_mut(ra_db::CrateGraphQuery)
.set((), Default::default());
db.query_mut(ra_db::LocalRootsQuery)
.set((), Default::default());
db.query_mut(ra_db::LibraryRootsQuery)
.set((), Default::default());
db.set_crate_graph(Default::default());
db.set_local_roots(Default::default());
db.set_library_roots(Default::default());
db
}
}
@ -54,7 +50,7 @@ impl salsa::ParallelDatabase for RootDatabase {
}
}
impl BaseDatabase for RootDatabase {}
impl CheckCanceled for RootDatabase {}
impl AsRef<hir::HirInterner> for RootDatabase {
fn as_ref(&self) -> &hir::HirInterner {
@ -63,11 +59,11 @@ impl AsRef<hir::HirInterner> for RootDatabase {
}
#[salsa::query_group(LineIndexDatabaseStorage)]
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
}
fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> {
fn line_index(db: &impl ra_db::SourceDatabase, file_id: FileId) -> Arc<LineIndex> {
let text = db.file_text(file_id);
Arc::new(LineIndex::new(&*text))
}

View file

@ -1,4 +1,4 @@
use ra_db::SyntaxDatabase;
use ra_db::SourceDatabase;
use ra_syntax::{
SyntaxNode, AstNode, SourceFile,
ast, algo::find_covering_node,

View file

@ -1,4 +1,4 @@
use ra_db::{FileId, SyntaxDatabase};
use ra_db::{FileId, SourceDatabase};
use ra_syntax::{
AstNode, ast,
algo::find_node_at_offset,

View file

@ -1,4 +1,4 @@
use ra_db::{SyntaxDatabase};
use ra_db::SourceDatabase;
use ra_syntax::{
AstNode, SyntaxNode, TreeArc, ast,
algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},

View file

@ -4,7 +4,7 @@ use hir::{
self, Problem, source_binder
};
use ra_db::{
FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase,
SourceDatabase, SourceRoot, SourceRootId,
salsa::{Database, SweepStrategy},
};
use ra_ide_api_light::{self, assists, LocalEdit, Severity};

View file

@ -34,7 +34,7 @@ use std::{fmt, sync::Arc};
use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
use ra_text_edit::TextEdit;
use ra_db::{
SyntaxDatabase, FilesDatabase, BaseDatabase,
SourceDatabase, CheckCanceled,
salsa::{self, ParallelDatabase},
};
use rayon::prelude::*;

View file

@ -17,7 +17,7 @@ use crate::{
SourceChange,
SourceFileEdit,
};
use ra_db::{FilesDatabase, SyntaxDatabase};
use ra_db::SourceDatabase;
use relative_path::RelativePath;
pub(crate) fn rename(

View file

@ -3,7 +3,7 @@ use ra_syntax::{
TextRange, SyntaxNode,
ast::{self, AstNode, NameOwner, ModuleItemOwner},
};
use ra_db::SyntaxDatabase;
use ra_db::SourceDatabase;
use crate::{db::RootDatabase, FileId};

View file

@ -34,7 +34,7 @@ use ra_syntax::{
ast::{self, NameOwner},
};
use ra_db::{
SourceRootId, FilesDatabase,
SourceRootId, SourceDatabase,
salsa::{self, ParallelDatabase},
};
use rayon::prelude::*;
@ -49,6 +49,14 @@ pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
fn file_symbols(&self, file_id: FileId) -> Arc<SymbolIndex>;
#[salsa::input]
fn library_symbols(&self, id: SourceRootId) -> Arc<SymbolIndex>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
#[salsa::input]
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
}
fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> {

View file

@ -1,5 +1,5 @@
use ra_syntax::{ast, AstNode,};
use ra_db::SyntaxDatabase;
use ra_db::SourceDatabase;
use crate::{
FileId, HighlightedRange,