rename FilesDatabase -> SourceDatabase

This commit is contained in:
Aleksey Kladov 2019-01-26 11:20:30 +03:00
parent 3223de5976
commit 4711cbcace
17 changed files with 27 additions and 25 deletions

View file

@ -63,8 +63,10 @@ pub struct FileRange {
pub range: TextRange, pub range: TextRange,
} }
#[salsa::query_group(FilesDatabaseStorage)] /// Database which stores all significant input facts: source code and project
pub trait FilesDatabase: salsa::Database + CheckCanceled { /// 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. /// Text of the file.
#[salsa::input] #[salsa::input]
fn file_text(&self, file_id: FileId) -> Arc<String>; fn file_text(&self, file_id: FileId) -> Arc<String>;
@ -85,7 +87,7 @@ pub trait FilesDatabase: salsa::Database + CheckCanceled {
fn crate_graph(&self) -> Arc<CrateGraph>; 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 root = db.source_root(id);
let graph = db.crate_graph(); let graph = db.crate_graph();
let res = root let res = root
@ -96,7 +98,7 @@ fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<Crat
Arc::new(res) Arc::new(res)
} }
fn source_file(db: &impl FilesDatabase, file_id: FileId) -> TreeArc<SourceFile> { fn source_file(db: &impl SourceDatabase, file_id: FileId) -> TreeArc<SourceFile> {
let text = db.file_text(file_id); let text = db.file_text(file_id);
SourceFile::parse(&*text) SourceFile::parse(&*text)
} }

View file

@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
use ra_db::{FilesDatabase, CrateId, salsa}; use ra_db::{SourceDatabase, CrateId, salsa};
use crate::{ use crate::{
MacroCallId, HirFileId, MacroCallId, HirFileId,
@ -19,7 +19,7 @@ use crate::{
}; };
#[salsa::query_group(HirDatabaseStorage)] #[salsa::query_group(HirDatabaseStorage)]
pub trait HirDatabase: FilesDatabase + AsRef<HirInterner> { pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> {
#[salsa::invoke(HirFileId::hir_source_file)] #[salsa::invoke(HirFileId::hir_source_file)]
fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>; 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 parking_lot::Mutex;
use ra_db::{ use ra_db::{
CheckCanceled, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase, salsa, CheckCanceled, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa,
}; };
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
@ -11,7 +11,7 @@ use crate::{db, HirInterner};
pub const WORKSPACE: SourceRootId = SourceRootId(0); pub const WORKSPACE: SourceRootId = SourceRootId(0);
#[salsa::database(ra_db::FilesDatabaseStorage, db::HirDatabaseStorage)] #[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage)]
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct MockDatabase { pub(crate) struct MockDatabase {
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,

View file

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

View file

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

View file

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

View file

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

View file

@ -1,14 +1,14 @@
use std::sync::Arc; use std::sync::Arc;
use ra_db::{ use ra_db::{
CheckCanceled, FileId, Canceled, FilesDatabase, CheckCanceled, FileId, Canceled, SourceDatabase,
salsa, salsa,
}; };
use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
#[salsa::database( #[salsa::database(
ra_db::FilesDatabaseStorage, ra_db::SourceDatabaseStorage,
LineIndexDatabaseStorage, LineIndexDatabaseStorage,
symbol_index::SymbolsDatabaseStorage, symbol_index::SymbolsDatabaseStorage,
hir::db::HirDatabaseStorage hir::db::HirDatabaseStorage
@ -59,11 +59,11 @@ impl AsRef<hir::HirInterner> for RootDatabase {
} }
#[salsa::query_group(LineIndexDatabaseStorage)] #[salsa::query_group(LineIndexDatabaseStorage)]
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + CheckCanceled { pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; 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); let text = db.file_text(file_id);
Arc::new(LineIndex::new(&*text)) Arc::new(LineIndex::new(&*text))
} }

View file

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

View file

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

View file

@ -1,4 +1,4 @@
use ra_db::FilesDatabase; use ra_db::SourceDatabase;
use ra_syntax::{ use ra_syntax::{
AstNode, SyntaxNode, TreeArc, ast, AstNode, SyntaxNode, TreeArc, ast,
algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, 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 self, Problem, source_binder
}; };
use ra_db::{ use ra_db::{
FilesDatabase, SourceRoot, SourceRootId, SourceDatabase, SourceRoot, SourceRootId,
salsa::{Database, SweepStrategy}, salsa::{Database, SweepStrategy},
}; };
use ra_ide_api_light::{self, assists, LocalEdit, Severity}; 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_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
use ra_text_edit::TextEdit; use ra_text_edit::TextEdit;
use ra_db::{ use ra_db::{
FilesDatabase, CheckCanceled, SourceDatabase, CheckCanceled,
salsa::{self, ParallelDatabase}, salsa::{self, ParallelDatabase},
}; };
use rayon::prelude::*; use rayon::prelude::*;

View file

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

View file

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

View file

@ -34,7 +34,7 @@ use ra_syntax::{
ast::{self, NameOwner}, ast::{self, NameOwner},
}; };
use ra_db::{ use ra_db::{
SourceRootId, FilesDatabase, SourceRootId, SourceDatabase,
salsa::{self, ParallelDatabase}, salsa::{self, ParallelDatabase},
}; };
use rayon::prelude::*; use rayon::prelude::*;

View file

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