aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 17:44:31 +0000
committerAleksey Kladov <[email protected]>2019-01-08 18:01:41 +0000
commit702bdacb03b498f36ed9ccf4f37ca923affb1e9c (patch)
tree36be9bf0d15ef94cde0821ebe441e5540520b59c /crates/ra_editor/src
parent1b82084a5f28506134c668a67d2759ef22be6a80 (diff)
move node at offset to aglo already
Diffstat (limited to 'crates/ra_editor/src')
-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
3 files changed, 3 insertions, 9 deletions
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() {