From 695294bbb974cdbac136e260029403e90a17d953 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 21:00:51 +0300 Subject: ra_db is independent from editor --- crates/ra_analysis/src/db.rs | 24 +++++++++++++++++++----- crates/ra_analysis/src/lib.rs | 12 +++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 1709be5cf..9d46609ec 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -1,10 +1,9 @@ use std::{fmt, sync::Arc}; + use salsa::{self, Database}; -use ra_db::{LocationIntener, BaseDatabase}; +use ra_db::{LocationIntener, BaseDatabase, FileId}; -use crate::{ - symbol_index, -}; +use crate::{symbol_index, LineIndex}; #[derive(Debug)] pub(crate) struct RootDatabase { @@ -71,6 +70,19 @@ impl AsRef> for RootDatabas } } +salsa::query_group! { + pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase { + fn line_index(file_id: FileId) -> Arc { + type LineIndexQuery; + } + } +} + +fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc { + let text = db.file_text(file_id); + Arc::new(LineIndex::new(&*text)) +} + salsa::database_storage! { pub(crate) struct RootDatabaseStorage for RootDatabase { impl ra_db::FilesDatabase { @@ -84,7 +96,9 @@ salsa::database_storage! { } impl ra_db::SyntaxDatabase { fn source_file() for ra_db::SourceFileQuery; - fn file_lines() for ra_db::FileLinesQuery; + } + impl LineIndexDatabase { + fn line_index() for LineIndexQuery; } impl symbol_index::SymbolsDatabase { fn file_symbols() for symbol_index::FileSymbolsQuery; diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index a3b350ad7..48df08416 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -29,12 +29,16 @@ use std::{fmt, sync::Arc}; use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; use ra_text_edit::TextEdit; +use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr}; use rayon::prelude::*; use relative_path::RelativePathBuf; use rustc_hash::FxHashMap; use salsa::ParallelDatabase; -use crate::symbol_index::{FileSymbol, SymbolIndex}; +use crate::{ + symbol_index::{FileSymbol, SymbolIndex}, + db::LineIndexDatabase, +}; pub use crate::{ completion::{CompletionItem, CompletionItemKind, InsertText}, @@ -44,10 +48,8 @@ pub use ra_editor::{ Fold, FoldKind, HighlightedRange, Severity, StructureNode, LineIndex, LineCol, translate_offset_with_edit, }; - pub use ra_db::{ - Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, FilesDatabase, - LocalSyntaxPtr, SourceRootId, SyntaxDatabase, + Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId }; #[derive(Default)] @@ -325,7 +327,7 @@ impl Analysis { /// Gets the file's `LineIndex`: data structure to convert between absolute /// offsets and line/column representation. pub fn file_line_index(&self, file_id: FileId) -> Arc { - self.db.file_lines(file_id) + self.db.line_index(file_id) } /// Selects the next syntactic nodes encopasing the range. pub fn extend_selection(&self, frange: FileRange) -> TextRange { -- cgit v1.2.3