Skip to content

make matching brace work when cursor not at bracket#21792

Merged
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
bend-n:make-matching-brace-almost-always-proc
Apr 5, 2026
Merged

make matching brace work when cursor not at bracket#21792
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
bend-n:make-matching-brace-almost-always-proc

Conversation

@bend-n
Copy link
Copy Markdown
Contributor

@bend-n bend-n commented Mar 10, 2026

by jumping to the parents enclosing bracket.

see #t-compiler/rust-analyzer > experimental/matching braces when not on a brace @ 💬

this would make the behavior match vscodes go to bracket command.

behavior pictured:

2026-03-10.17-53-48.mp4

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2026
Comment thread crates/ide/src/matching_brace.rs Outdated
Some(matching_node.text_range().start())
} else {
// when the offset is not at a brace
let thingy = file.syntax().token_at_offset(offset).last()?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have file.syntax().token_at_offset(offset). There is a potential for code reuse here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also thingy is not exactly a descriptive name.

Comment thread crates/ide/src/matching_brace.rs
@bend-n bend-n force-pushed the make-matching-brace-almost-always-proc branch from 89cb5dd to 53ceaf7 Compare March 23, 2026 07:54
let parent = brace_token.parent()?;
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
cov_mark::hit!(pipes_not_braces);
return None;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? I see no reason to exclude pipes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats not my code, its from #5047

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 5, 2026
Merged via the queue into rust-lang:master with commit c834a52 Apr 5, 2026
17 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants