diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/db.rs | 24 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ra_db/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 1 |
7 files changed, 27 insertions, 23 deletions
diff --git a/Cargo.lock b/Cargo.lock index 318fea893..c445439b1 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -679,7 +679,6 @@ version = "0.1.0" | |||
679 | dependencies = [ | 679 | dependencies = [ |
680 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 680 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
681 | "ra_arena 0.1.0", | 681 | "ra_arena 0.1.0", |
682 | "ra_editor 0.1.0", | ||
683 | "ra_syntax 0.1.0", | 682 | "ra_syntax 0.1.0", |
684 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | 683 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
685 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 684 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
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 @@ | |||
1 | use std::{fmt, sync::Arc}; | 1 | use std::{fmt, sync::Arc}; |
2 | |||
2 | use salsa::{self, Database}; | 3 | use salsa::{self, Database}; |
3 | use ra_db::{LocationIntener, BaseDatabase}; | 4 | use ra_db::{LocationIntener, BaseDatabase, FileId}; |
4 | 5 | ||
5 | use crate::{ | 6 | use crate::{symbol_index, LineIndex}; |
6 | symbol_index, | ||
7 | }; | ||
8 | 7 | ||
9 | #[derive(Debug)] | 8 | #[derive(Debug)] |
10 | pub(crate) struct RootDatabase { | 9 | pub(crate) struct RootDatabase { |
@@ -71,6 +70,19 @@ impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabas | |||
71 | } | 70 | } |
72 | } | 71 | } |
73 | 72 | ||
73 | salsa::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 | |||
81 | fn 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 | |||
74 | salsa::database_storage! { | 86 | salsa::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 | ||
30 | use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; | 30 | use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; |
31 | use ra_text_edit::TextEdit; | 31 | use ra_text_edit::TextEdit; |
32 | use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr}; | ||
32 | use rayon::prelude::*; | 33 | use rayon::prelude::*; |
33 | use relative_path::RelativePathBuf; | 34 | use relative_path::RelativePathBuf; |
34 | use rustc_hash::FxHashMap; | 35 | use rustc_hash::FxHashMap; |
35 | use salsa::ParallelDatabase; | 36 | use salsa::ParallelDatabase; |
36 | 37 | ||
37 | use crate::symbol_index::{FileSymbol, SymbolIndex}; | 38 | use crate::{ |
39 | symbol_index::{FileSymbol, SymbolIndex}, | ||
40 | db::LineIndexDatabase, | ||
41 | }; | ||
38 | 42 | ||
39 | pub use crate::{ | 43 | pub 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 | |||
48 | pub use ra_db::{ | 51 | pub 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 { |
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index c43e65051..2c1f94ad0 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -11,5 +11,4 @@ rustc-hash = "1.0" | |||
11 | parking_lot = "0.7.0" | 11 | parking_lot = "0.7.0" |
12 | ra_arena = { path = "../ra_arena" } | 12 | ra_arena = { path = "../ra_arena" } |
13 | ra_syntax = { path = "../ra_syntax" } | 13 | ra_syntax = { path = "../ra_syntax" } |
14 | ra_editor = { path = "../ra_editor" } | ||
15 | test_utils = { path = "../test_utils" } | 14 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 732899718..f56f70983 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -5,9 +5,6 @@ mod input; | |||
5 | mod loc2id; | 5 | mod loc2id; |
6 | pub mod mock; | 6 | pub mod mock; |
7 | 7 | ||
8 | use std::sync::Arc; | ||
9 | |||
10 | use ra_editor::LineIndex; | ||
11 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; | 8 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; |
12 | 9 | ||
13 | pub use crate::{ | 10 | pub use crate::{ |
@@ -36,9 +33,6 @@ salsa::query_group! { | |||
36 | fn source_file(file_id: FileId) -> TreePtr<SourceFile> { | 33 | fn source_file(file_id: FileId) -> TreePtr<SourceFile> { |
37 | type SourceFileQuery; | 34 | type SourceFileQuery; |
38 | } | 35 | } |
39 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { | ||
40 | type FileLinesQuery; | ||
41 | } | ||
42 | } | 36 | } |
43 | } | 37 | } |
44 | 38 | ||
@@ -46,10 +40,6 @@ fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreePtr<SourceFile> | |||
46 | let text = db.file_text(file_id); | 40 | let text = db.file_text(file_id); |
47 | SourceFile::parse(&*text) | 41 | SourceFile::parse(&*text) |
48 | } | 42 | } |
49 | fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { | ||
50 | let text = db.file_text(file_id); | ||
51 | Arc::new(LineIndex::new(&*text)) | ||
52 | } | ||
53 | 43 | ||
54 | #[derive(Clone, Copy, Debug)] | 44 | #[derive(Clone, Copy, Debug)] |
55 | pub struct FilePosition { | 45 | pub struct FilePosition { |
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index c9af38009..0fae7de82 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -215,7 +215,6 @@ salsa::database_storage! { | |||
215 | } | 215 | } |
216 | impl ra_db::SyntaxDatabase { | 216 | impl ra_db::SyntaxDatabase { |
217 | fn source_file() for ra_db::SourceFileQuery; | 217 | fn source_file() for ra_db::SourceFileQuery; |
218 | fn file_lines() for ra_db::FileLinesQuery; | ||
219 | } | 218 | } |
220 | impl db::HirDatabase { | 219 | impl db::HirDatabase { |
221 | fn hir_source_file() for db::HirSourceFileQuery; | 220 | fn hir_source_file() for db::HirSourceFileQuery; |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 8adeedddb..90ba393ce 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -1049,6 +1049,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { | 1051 | pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { |
1052 | db.check_canceled()?; | ||
1052 | let function = Function::new(def_id); // TODO: consts also need inference | 1053 | let function = Function::new(def_id); // TODO: consts also need inference |
1053 | let body = function.body(db)?; | 1054 | let body = function.body(db)?; |
1054 | let scopes = db.fn_scopes(def_id)?; | 1055 | let scopes = db.fn_scopes(def_id)?; |