aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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/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_editor/src/assists.rs4
-rw-r--r--crates/ra_editor/src/lib.rs4
-rw-r--r--crates/ra_editor/src/typing.rs4
-rw-r--r--crates/ra_hir/src/code_model_impl/function/scope.rs3
-rw-r--r--crates/ra_hir/src/source_binder.rs2
-rw-r--r--crates/ra_syntax/src/algo.rs6
11 files changed, 19 insertions, 22 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/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_editor/src/assists.rs b/crates/ra_editor/src/assists.rs
index f839f6a7a..83eabfc85 100644
--- a/crates/ra_editor/src/assists.rs
+++ b/crates/ra_editor/src/assists.rs
@@ -14,13 +14,11 @@ mod replace_if_let_with_match;
14use ra_text_edit::{TextEdit, TextEditBuilder}; 14use ra_text_edit::{TextEdit, TextEditBuilder};
15use ra_syntax::{ 15use ra_syntax::{
16 Direction, SyntaxNode, TextUnit, TextRange, SourceFile, AstNode, 16 Direction, SyntaxNode, TextUnit, TextRange, SourceFile, AstNode,
17 algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, 17 algo::{find_leaf_at_offset, find_node_at_offset, find_covering_node, LeafAtOffset},
18 ast::{self, AstToken}, 18 ast::{self, AstToken},
19}; 19};
20use itertools::Itertools; 20use itertools::Itertools;
21 21
22use crate::find_node_at_offset;
23
24pub use self::{ 22pub use self::{
25 flip_comma::flip_comma, 23 flip_comma::flip_comma,
26 add_derive::add_derive, 24 add_derive::add_derive,
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index 6731260a3..5a6af19b7 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -120,10 +120,6 @@ pub fn syntax_tree(file: &SourceFile) -> String {
120 ::ra_syntax::utils::dump_tree(file.syntax()) 120 ::ra_syntax::utils::dump_tree(file.syntax())
121} 121}
122 122
123pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
124 find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
125}
126
127#[cfg(test)] 123#[cfg(test)]
128mod tests { 124mod tests {
129 use ra_syntax::AstNode; 125 use ra_syntax::AstNode;
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 5b260d2ac..576caf6be 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -2,7 +2,7 @@ use std::mem;
2 2
3use itertools::Itertools; 3use itertools::Itertools;
4use ra_syntax::{ 4use ra_syntax::{
5 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, 5 algo::{find_node_at_offset, find_covering_node, find_leaf_at_offset, LeafAtOffset},
6 ast, 6 ast,
7 text_utils::intersect, 7 text_utils::intersect,
8 AstNode, Direction, SourceFile, SyntaxKind, 8 AstNode, Direction, SourceFile, SyntaxKind,
@@ -11,7 +11,7 @@ use ra_syntax::{
11}; 11};
12use ra_text_edit::text_utils::contains_offset_nonstrict; 12use ra_text_edit::text_utils::contains_offset_nonstrict;
13 13
14use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; 14use crate::{LocalEdit, TextEditBuilder};
15 15
16pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { 16pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
17 let range = if range.is_empty() { 17 let range = if range.is_empty() {
diff --git a/crates/ra_hir/src/code_model_impl/function/scope.rs b/crates/ra_hir/src/code_model_impl/function/scope.rs
index 699784f71..ebf6edc1b 100644
--- a/crates/ra_hir/src/code_model_impl/function/scope.rs
+++ b/crates/ra_hir/src/code_model_impl/function/scope.rs
@@ -308,8 +308,7 @@ pub struct ReferenceDescriptor {
308 308
309#[cfg(test)] 309#[cfg(test)]
310mod tests { 310mod tests {
311 use ra_editor::find_node_at_offset; 311 use ra_syntax::{SourceFile, algo::find_node_at_offset};
312 use ra_syntax::SourceFile;
313 use test_utils::{extract_offset, assert_eq_text}; 312 use test_utils::{extract_offset, assert_eq_text};
314 313
315 use crate::expr; 314 use crate::expr;
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 59a803761..4b0400cd0 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -6,10 +6,10 @@
6/// So, this modules should not be used during hir construction, it exists 6/// So, this modules should not be used during hir construction, it exists
7/// purely for "IDE needs". 7/// purely for "IDE needs".
8use ra_db::{FileId, FilePosition, Cancelable}; 8use ra_db::{FileId, FilePosition, Cancelable};
9use ra_editor::find_node_at_offset;
10use ra_syntax::{ 9use ra_syntax::{
11 SmolStr, TextRange, SyntaxNode, 10 SmolStr, TextRange, SyntaxNode,
12 ast::{self, AstNode, NameOwner}, 11 ast::{self, AstNode, NameOwner},
12 algo::find_node_at_offset,
13}; 13};
14 14
15use crate::{ 15use crate::{
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs
index 13f50d2ef..2826ec7f2 100644
--- a/crates/ra_syntax/src/algo.rs
+++ b/crates/ra_syntax/src/algo.rs
@@ -2,7 +2,7 @@ pub mod visit;
2 2
3use rowan::TransparentNewType; 3use rowan::TransparentNewType;
4 4
5use crate::{SyntaxNode, TextRange, TextUnit}; 5use crate::{SyntaxNode, TextRange, TextUnit, AstNode};
6 6
7pub use rowan::LeafAtOffset; 7pub use rowan::LeafAtOffset;
8 8
@@ -16,6 +16,10 @@ pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<
16 } 16 }
17} 17}
18 18
19pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
20 find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
21}
22
19pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { 23pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode {
20 SyntaxNode::from_repr(root.0.covering_node(range)) 24 SyntaxNode::from_repr(root.0.covering_node(range))
21} 25}