aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 18:00:51 +0000
committerAleksey Kladov <[email protected]>2019-01-08 18:03:42 +0000
commit695294bbb974cdbac136e260029403e90a17d953 (patch)
treecaa02f8086ad15fb6f884e56bc6a0231b203215f /crates/ra_analysis/src
parent0c88360eb46c44935421c5d4bc36910ce3e96782 (diff)
ra_db is independent from editor
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/db.rs24
-rw-r--r--crates/ra_analysis/src/lib.rs12
2 files changed, 26 insertions, 10 deletions
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 @@
1use std::{fmt, sync::Arc}; 1use std::{fmt, sync::Arc};
2
2use salsa::{self, Database}; 3use salsa::{self, Database};
3use ra_db::{LocationIntener, BaseDatabase}; 4use ra_db::{LocationIntener, BaseDatabase, FileId};
4 5
5use crate::{ 6use crate::{symbol_index, LineIndex};
6 symbol_index,
7};
8 7
9#[derive(Debug)] 8#[derive(Debug)]
10pub(crate) struct RootDatabase { 9pub(crate) struct RootDatabase {
@@ -71,6 +70,19 @@ impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabas
71 } 70 }
72} 71}
73 72
73salsa::query_group! {
74 pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
75 fn line_index(file_id: FileId) -> Arc<LineIndex> {
76 type LineIndexQuery;
77 }
78 }
79}
80
81fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> {
82 let text = db.file_text(file_id);
83 Arc::new(LineIndex::new(&*text))
84}
85
74salsa::database_storage! { 86salsa::database_storage! {
75 pub(crate) struct RootDatabaseStorage for RootDatabase { 87 pub(crate) struct RootDatabaseStorage for RootDatabase {
76 impl ra_db::FilesDatabase { 88 impl ra_db::FilesDatabase {
@@ -84,7 +96,9 @@ salsa::database_storage! {
84 } 96 }
85 impl ra_db::SyntaxDatabase { 97 impl ra_db::SyntaxDatabase {
86 fn source_file() for ra_db::SourceFileQuery; 98 fn source_file() for ra_db::SourceFileQuery;
87 fn file_lines() for ra_db::FileLinesQuery; 99 }
100 impl LineIndexDatabase {
101 fn line_index() for LineIndexQuery;
88 } 102 }
89 impl symbol_index::SymbolsDatabase { 103 impl symbol_index::SymbolsDatabase {
90 fn file_symbols() for symbol_index::FileSymbolsQuery; 104 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};
29 29
30use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; 30use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit};
31use ra_text_edit::TextEdit; 31use ra_text_edit::TextEdit;
32use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr};
32use rayon::prelude::*; 33use rayon::prelude::*;
33use relative_path::RelativePathBuf; 34use relative_path::RelativePathBuf;
34use rustc_hash::FxHashMap; 35use rustc_hash::FxHashMap;
35use salsa::ParallelDatabase; 36use salsa::ParallelDatabase;
36 37
37use crate::symbol_index::{FileSymbol, SymbolIndex}; 38use crate::{
39 symbol_index::{FileSymbol, SymbolIndex},
40 db::LineIndexDatabase,
41};
38 42
39pub use crate::{ 43pub use crate::{
40 completion::{CompletionItem, CompletionItemKind, InsertText}, 44 completion::{CompletionItem, CompletionItemKind, InsertText},
@@ -44,10 +48,8 @@ pub use ra_editor::{
44 Fold, FoldKind, HighlightedRange, Severity, StructureNode, 48 Fold, FoldKind, HighlightedRange, Severity, StructureNode,
45 LineIndex, LineCol, translate_offset_with_edit, 49 LineIndex, LineCol, translate_offset_with_edit,
46}; 50};
47
48pub use ra_db::{ 51pub use ra_db::{
49 Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, FilesDatabase, 52 Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
50 LocalSyntaxPtr, SourceRootId, SyntaxDatabase,
51}; 53};
52 54
53#[derive(Default)] 55#[derive(Default)]
@@ -325,7 +327,7 @@ impl Analysis {
325 /// Gets the file's `LineIndex`: data structure to convert between absolute 327 /// Gets the file's `LineIndex`: data structure to convert between absolute
326 /// offsets and line/column representation. 328 /// offsets and line/column representation.
327 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 329 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
328 self.db.file_lines(file_id) 330 self.db.line_index(file_id)
329 } 331 }
330 /// Selects the next syntactic nodes encopasing the range. 332 /// Selects the next syntactic nodes encopasing the range.
331 pub fn extend_selection(&self, frange: FileRange) -> TextRange { 333 pub fn extend_selection(&self, frange: FileRange) -> TextRange {