aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 18:04:08 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 18:04:08 +0000
commitc9e42fcf245be16958dca6571e4bccc6c29199df (patch)
treecaa02f8086ad15fb6f884e56bc6a0231b203215f /crates/ra_analysis/src
parent1c25bf05d714680c048d250a5d39e8a4c25f0c31 (diff)
parent695294bbb974cdbac136e260029403e90a17d953 (diff)
Merge #468
468: decouple ra_editor from other stuff r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/call_info.rs2
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs3
-rw-r--r--crates/ra_analysis/src/db.rs24
-rw-r--r--crates/ra_analysis/src/goto_defenition.rs7
-rw-r--r--crates/ra_analysis/src/hover.rs3
-rw-r--r--crates/ra_analysis/src/imp.rs3
-rw-r--r--crates/ra_analysis/src/lib.rs17
7 files changed, 39 insertions, 20 deletions
diff --git a/crates/ra_analysis/src/call_info.rs b/crates/ra_analysis/src/call_info.rs
index 1dac95584..27b760780 100644
--- a/crates/ra_analysis/src/call_info.rs
+++ b/crates/ra_analysis/src/call_info.rs
@@ -5,8 +5,8 @@ use ra_syntax::{
5 AstNode, SyntaxNode, TextUnit, TextRange, 5 AstNode, SyntaxNode, TextUnit, TextRange,
6 SyntaxKind::FN_DEF, 6 SyntaxKind::FN_DEF,
7 ast::{self, ArgListOwner, DocCommentsOwner}, 7 ast::{self, ArgListOwner, DocCommentsOwner},
8 algo::find_node_at_offset,
8}; 9};
9use ra_editor::find_node_at_offset;
10 10
11use crate::{FilePosition, CallInfo, db::RootDatabase}; 11use crate::{FilePosition, CallInfo, db::RootDatabase};
12 12
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs
index 988c21c58..01786bb69 100644
--- a/crates/ra_analysis/src/completion/completion_context.rs
+++ b/crates/ra_analysis/src/completion/completion_context.rs
@@ -1,9 +1,8 @@
1use ra_editor::find_node_at_offset;
2use ra_text_edit::AtomTextEdit; 1use ra_text_edit::AtomTextEdit;
3use ra_syntax::{ 2use ra_syntax::{
4 AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, 3 AstNode, SyntaxNode, SourceFile, TextUnit, TextRange,
5 ast, 4 ast,
6 algo::{find_leaf_at_offset, find_covering_node}, 5 algo::{find_leaf_at_offset, find_covering_node, find_node_at_offset},
7 SyntaxKind::*, 6 SyntaxKind::*,
8}; 7};
9use hir::source_binder; 8use hir::source_binder;
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/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs
index 0bcf13ebd..fcd8d315e 100644
--- a/crates/ra_analysis/src/goto_defenition.rs
+++ b/crates/ra_analysis/src/goto_defenition.rs
@@ -1,7 +1,8 @@
1use ra_db::{FileId, Cancelable, SyntaxDatabase}; 1use ra_db::{FileId, Cancelable, SyntaxDatabase};
2use ra_syntax::{TextRange, AstNode, ast, SyntaxKind::{NAME, MODULE}}; 2use ra_syntax::{
3 3 TextRange, AstNode, ast, SyntaxKind::{NAME, MODULE},
4use ra_editor::find_node_at_offset; 4 algo::find_node_at_offset,
5};
5 6
6use crate::{FilePosition, NavigationTarget, db::RootDatabase}; 7use crate::{FilePosition, NavigationTarget, db::RootDatabase};
7 8
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs
index 5607c3ef3..475524ee1 100644
--- a/crates/ra_analysis/src/hover.rs
+++ b/crates/ra_analysis/src/hover.rs
@@ -1,9 +1,8 @@
1use ra_db::{Cancelable, SyntaxDatabase}; 1use ra_db::{Cancelable, SyntaxDatabase};
2use ra_editor::find_node_at_offset;
3use ra_syntax::{ 2use ra_syntax::{
4 AstNode, SyntaxNode, TreePtr, 3 AstNode, SyntaxNode, TreePtr,
5 ast::{self, NameOwner}, 4 ast::{self, NameOwner},
6 algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, 5 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},
7}; 6};
8 7
9use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; 8use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index b3f75fdbe..2b9963b3c 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -6,10 +6,11 @@ use hir::{
6 self, Problem, source_binder, 6 self, Problem, source_binder,
7}; 7};
8use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; 8use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
9use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; 9use ra_editor::{self, assists, LocalEdit, Severity};
10use ra_syntax::{ 10use ra_syntax::{
11 TextRange, AstNode, SourceFile, 11 TextRange, AstNode, SourceFile,
12 ast::{self, NameOwner}, 12 ast::{self, NameOwner},
13 algo::find_node_at_offset,
13 SyntaxKind::*, 14 SyntaxKind::*,
14}; 15};
15 16
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 771a349c8..48df08416 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -29,22 +29,27 @@ 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},
41 runnables::{Runnable, RunnableKind}, 45 runnables::{Runnable, RunnableKind},
42}; 46};
43pub use ra_editor::{Fold, FoldKind, HighlightedRange, LineIndex, Severity, StructureNode}; 47pub use ra_editor::{
44 48 Fold, FoldKind, HighlightedRange, Severity, StructureNode,
49 LineIndex, LineCol, translate_offset_with_edit,
50};
45pub use ra_db::{ 51pub use ra_db::{
46 Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, FilesDatabase, 52 Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
47 LocalSyntaxPtr, SourceRootId, SyntaxDatabase,
48}; 53};
49 54
50#[derive(Default)] 55#[derive(Default)]
@@ -322,7 +327,7 @@ impl Analysis {
322 /// Gets the file's `LineIndex`: data structure to convert between absolute 327 /// Gets the file's `LineIndex`: data structure to convert between absolute
323 /// offsets and line/column representation. 328 /// offsets and line/column representation.
324 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 329 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
325 self.db.file_lines(file_id) 330 self.db.line_index(file_id)
326 } 331 }
327 /// Selects the next syntactic nodes encopasing the range. 332 /// Selects the next syntactic nodes encopasing the range.
328 pub fn extend_selection(&self, frange: FileRange) -> TextRange { 333 pub fn extend_selection(&self, frange: FileRange) -> TextRange {