aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/matching_brace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/matching_brace.rs')
-rw-r--r--crates/ra_ide_api/src/matching_brace.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs
index d1405f14f..bebd16a69 100644
--- a/crates/ra_ide_api/src/matching_brace.rs
+++ b/crates/ra_ide_api/src/matching_brace.rs
@@ -1,6 +1,6 @@
1use ra_syntax::{ 1use ra_syntax::{
2 SourceFile, TextUnit, 2 SourceFile, TextUnit,
3 algo::find_leaf_at_offset, 3 algo::find_token_at_offset,
4 SyntaxKind::{self, *}, 4 SyntaxKind::{self, *},
5 ast::AstNode, 5 ast::AstNode,
6}; 6};
@@ -8,15 +8,15 @@ use ra_syntax::{
8pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { 8pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> {
9 const BRACES: &[SyntaxKind] = 9 const BRACES: &[SyntaxKind] =
10 &[L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE]; 10 &[L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE];
11 let (brace_node, brace_idx) = find_leaf_at_offset(file.syntax(), offset) 11 let (brace_node, brace_idx) = find_token_at_offset(file.syntax(), offset)
12 .filter_map(|node| { 12 .filter_map(|node| {
13 let idx = BRACES.iter().position(|&brace| brace == node.kind())?; 13 let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
14 Some((node, idx)) 14 Some((node, idx))
15 }) 15 })
16 .next()?; 16 .next()?;
17 let parent = brace_node.parent()?; 17 let parent = brace_node.parent();
18 let matching_kind = BRACES[brace_idx ^ 1]; 18 let matching_kind = BRACES[brace_idx ^ 1];
19 let matching_node = parent.children().find(|node| node.kind() == matching_kind)?; 19 let matching_node = parent.children_with_tokens().find(|node| node.kind() == matching_kind)?;
20 Some(matching_node.range().start()) 20 Some(matching_node.range().start())
21} 21}
22 22
@@ -41,5 +41,4 @@ mod tests {
41 41
42 do_check("struct Foo { a: i32, }<|>", "struct Foo <|>{ a: i32, }"); 42 do_check("struct Foo { a: i32, }<|>", "struct Foo <|>{ a: i32, }");
43 } 43 }
44
45} 44}