fold syntax database into files database

This commit is contained in:
Aleksey Kladov 2019-01-26 11:09:39 +03:00
parent 2f270a51d2
commit be1a005ebd
15 changed files with 24 additions and 32 deletions

View file

@ -20,7 +20,7 @@ pub use crate::{
loc2id::LocationIntener, loc2id::LocationIntener,
}; };
pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { pub trait CheckCanceled: salsa::Database + panic::RefUnwindSafe {
/// Aborts current query if there are pending changes. /// Aborts current query if there are pending changes.
/// ///
/// rust-analyzer needs to be able to answer semantic questions about the /// rust-analyzer needs to be able to answer semantic questions about the
@ -64,10 +64,12 @@ pub struct FileRange {
} }
#[salsa::query_group(FilesDatabaseStorage)] #[salsa::query_group(FilesDatabaseStorage)]
pub trait FilesDatabase: salsa::Database { pub trait FilesDatabase: 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>;
// 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. /// Path to a file, relative to the root of its source root.
#[salsa::input] #[salsa::input]
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf; fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
@ -102,12 +104,7 @@ fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<Crat
Arc::new(res) Arc::new(res)
} }
#[salsa::query_group(SyntaxDatabaseStorage)] fn source_file(db: &impl FilesDatabase, file_id: FileId) -> TreeArc<SourceFile> {
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> {
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::{SyntaxDatabase, CrateId, salsa}; use ra_db::{FilesDatabase, 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: SyntaxDatabase + AsRef<HirInterner> { pub trait HirDatabase: FilesDatabase + 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::{
BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase, salsa, CheckCanceled, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase, 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,11 +11,7 @@ use crate::{db, HirInterner};
pub const WORKSPACE: SourceRootId = SourceRootId(0); pub const WORKSPACE: SourceRootId = SourceRootId(0);
#[salsa::database( #[salsa::database(ra_db::FilesDatabaseStorage, db::HirDatabaseStorage)]
ra_db::FilesDatabaseStorage,
ra_db::SyntaxDatabaseStorage,
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>>>>,
@ -161,7 +157,7 @@ impl salsa::ParallelDatabase for MockDatabase {
} }
} }
impl BaseDatabase for MockDatabase {} impl CheckCanceled for MockDatabase {}
impl AsRef<HirInterner> for MockDatabase { impl AsRef<HirInterner> for MockDatabase {
fn as_ref(&self) -> &HirInterner { fn as_ref(&self) -> &HirInterner {

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::{SyntaxDatabase, salsa::Database}; use ra_db::{FilesDatabase, 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::SyntaxDatabase; use ra_db::FilesDatabase;
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::SyntaxDatabase; use ra_db::FilesDatabase;
use crate::{ use crate::{
db, db,

View file

@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use ra_db::{ use ra_db::{
BaseDatabase, FileId, Canceled, CheckCanceled, FileId, Canceled,
salsa::{self, Database}, salsa::{self, Database},
}; };
@ -9,7 +9,6 @@ use crate::{symbol_index, LineIndex};
#[salsa::database( #[salsa::database(
ra_db::FilesDatabaseStorage, ra_db::FilesDatabaseStorage,
ra_db::SyntaxDatabaseStorage,
LineIndexDatabaseStorage, LineIndexDatabaseStorage,
symbol_index::SymbolsDatabaseStorage, symbol_index::SymbolsDatabaseStorage,
hir::db::HirDatabaseStorage hir::db::HirDatabaseStorage
@ -54,7 +53,7 @@ impl salsa::ParallelDatabase for RootDatabase {
} }
} }
impl BaseDatabase for RootDatabase {} impl CheckCanceled for RootDatabase {}
impl AsRef<hir::HirInterner> for RootDatabase { impl AsRef<hir::HirInterner> for RootDatabase {
fn as_ref(&self) -> &hir::HirInterner { fn as_ref(&self) -> &hir::HirInterner {
@ -63,7 +62,7 @@ impl AsRef<hir::HirInterner> for RootDatabase {
} }
#[salsa::query_group(LineIndexDatabaseStorage)] #[salsa::query_group(LineIndexDatabaseStorage)]
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase { pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + CheckCanceled {
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
} }

View file

@ -1,4 +1,4 @@
use ra_db::SyntaxDatabase; use ra_db::FilesDatabase;
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, SyntaxDatabase}; use ra_db::{FileId, FilesDatabase};
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::{SyntaxDatabase}; use ra_db::FilesDatabase;
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, SyntaxDatabase, FilesDatabase, 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::{
SyntaxDatabase, FilesDatabase, BaseDatabase, FilesDatabase, 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, SyntaxDatabase}; use ra_db::FilesDatabase;
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::SyntaxDatabase; use ra_db::FilesDatabase;
use crate::{db::RootDatabase, FileId}; use crate::{db::RootDatabase, FileId};

View file

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