diff options
Diffstat (limited to 'crates/libeditor')
-rw-r--r-- | crates/libeditor/src/code_actions.rs | 10 | ||||
-rw-r--r-- | crates/libeditor/tests/test.rs | 8 |
2 files changed, 9 insertions, 9 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index 6df64be12..4b2515835 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs | |||
@@ -71,13 +71,11 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta | |||
71 | .find(|node| !node.kind().is_trivia()) | 71 | .find(|node| !node.kind().is_trivia()) |
72 | } | 72 | } |
73 | 73 | ||
74 | fn find_non_trivia_leaf(syntax: SyntaxNodeRef, offset: TextUnit) -> Option<SyntaxNodeRef> { | ||
75 | find_leaf_at_offset(syntax, offset) | ||
76 | .find(|leaf| !leaf.kind().is_trivia()) | ||
77 | } | ||
78 | |||
79 | pub fn find_node<'a, N: AstNode<&'a SyntaxRoot>>(syntax: SyntaxNodeRef<'a>, offset: TextUnit) -> Option<N> { | 74 | pub fn find_node<'a, N: AstNode<&'a SyntaxRoot>>(syntax: SyntaxNodeRef<'a>, offset: TextUnit) -> Option<N> { |
80 | let leaf = find_non_trivia_leaf(syntax, offset)?; | 75 | let leaves = find_leaf_at_offset(syntax, offset); |
76 | let leaf = leaves.clone() | ||
77 | .find(|leaf| !leaf.kind().is_trivia()) | ||
78 | .or_else(|| leaves.right_biased())?; | ||
81 | ancestors(leaf) | 79 | ancestors(leaf) |
82 | .filter_map(N::cast) | 80 | .filter_map(N::cast) |
83 | .next() | 81 | .next() |
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index df4cb65d1..cc4226710 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs | |||
@@ -1,11 +1,8 @@ | |||
1 | extern crate libeditor; | 1 | extern crate libeditor; |
2 | extern crate libsyntax2; | 2 | extern crate libsyntax2; |
3 | extern crate itertools; | ||
4 | #[macro_use] | 3 | #[macro_use] |
5 | extern crate assert_eq_text; | 4 | extern crate assert_eq_text; |
6 | 5 | ||
7 | use std::fmt; | ||
8 | use itertools::Itertools; | ||
9 | use assert_eq_text::{assert_eq_dbg}; | 6 | use assert_eq_text::{assert_eq_dbg}; |
10 | use libeditor::{ | 7 | use libeditor::{ |
11 | File, TextUnit, TextRange, ActionResult, CursorPosition, | 8 | File, TextUnit, TextRange, ActionResult, CursorPosition, |
@@ -119,6 +116,11 @@ fn test_add_derive() { | |||
119 | |file, off| add_derive(file, off).map(|f| f()), | 116 | |file, off| add_derive(file, off).map(|f| f()), |
120 | ); | 117 | ); |
121 | check_action( | 118 | check_action( |
119 | "struct Foo { <|> a: i32, }", | ||
120 | "#[derive(<|>)]\nstruct Foo { a: i32, }", | ||
121 | |file, off| add_derive(file, off).map(|f| f()), | ||
122 | ); | ||
123 | check_action( | ||
122 | "#[derive(Clone)]\nstruct Foo { a: i32<|>, }", | 124 | "#[derive(Clone)]\nstruct Foo { a: i32<|>, }", |
123 | "#[derive(Clone<|>)]\nstruct Foo { a: i32, }", | 125 | "#[derive(Clone<|>)]\nstruct Foo { a: i32, }", |
124 | |file, off| add_derive(file, off).map(|f| f()), | 126 | |file, off| add_derive(file, off).map(|f| f()), |