Skip to content

Commit 53ceaf7

Browse files
committed
test
1 parent b54a6f3 commit 53ceaf7

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

crates/ide/src/matching_brace.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ use syntax::{
1717
pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> {
1818
const BRACES: &[SyntaxKind] =
1919
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]];
20-
21-
if let Some((brace_token, brace_idx)) = file
22-
.syntax()
23-
.token_at_offset(offset)
20+
let current = file.syntax().token_at_offset(offset);
21+
if let Some((brace_token, brace_idx)) = current
22+
.clone()
2423
.filter_map(|node| {
2524
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
2625
Some((node, idx))
@@ -39,10 +38,8 @@ pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<Text
3938
.find(|node| node.kind() == matching_kind && node != &brace_token)?;
4039
Some(matching_node.text_range().start())
4140
} else {
42-
// when the offset is not at a brace
43-
let thingy = file.syntax().token_at_offset(offset).last()?;
44-
// find first parent
45-
thingy.parent_ancestors().find_map(|x| {
41+
// when the offset is not at a brace, find first parent
42+
current.last()?.parent_ancestors().find_map(|x| {
4643
x.children_with_tokens()
4744
.filter_map(|it| it.into_token())
4845
// with ending brace
@@ -79,6 +76,14 @@ mod tests {
7976
"fn func(x) { return (2 * (x + 3)$0) + 5;}",
8077
"fn func(x) { return $0(2 * (x + 3)) + 5;}",
8178
);
79+
do_check(
80+
"fn func(x) { return (2 * (x $0+ 3)) + 5;}",
81+
"fn func(x) { return (2 * (x + 3$0)) + 5;}",
82+
);
83+
do_check(
84+
"fn func(x) { re$0turn (2 * (x + 3)) + 5;}",
85+
"fn func(x) { return (2 * (x + 3)) + 5;$0}",
86+
);
8287

8388
{
8489
cov_mark::check!(pipes_not_braces);

0 commit comments

Comments
 (0)