Implement text-based matching bracket logic for Vim '%' motion to correctly find pairs within comments#45559
Conversation
…rectly find pairs within comments.
dinocosta
left a comment
There was a problem hiding this comment.
Hey @tacshi ! 👋
Thank you for tackling this and for including tests, appreciate it! I've tested and reviewed these changes, everything looks good to me.
I've left some suggestions but they're non-blocking so if you don't want to tackle those, let me know and I can merge this! 🙂
…ing `line_range` conversions, and reorganizing variable declarations
|
@dinocosta |
There was a problem hiding this comment.
Pull request overview
This PR enhances Vim's '%' motion to support text-based bracket matching as a fallback mechanism when language-based syntax tree matching is unavailable or fails. This improvement ensures that bracket matching works correctly within comments and in buffers without language support, bringing Zed's Vim emulation closer to actual Vim behavior.
Key Changes:
- Implemented a text-based bracket matching algorithm that searches for and matches brackets using depth counting
- Modified the
matching()function to fall back to text-based matching when syntax-based matching returns no results - Added comprehensive test coverage for bracket matching in comments and template-style syntax
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/vim/src/motion.rs |
Adds text-based bracket matching functions (get_bracket_pair, find_matching_bracket_text_based) and integrates them as fallback logic in the matching() function |
crates/vim/test_data/test_percent_in_comment.json |
Provides 62 test cases covering bracket matching in comments, nested brackets, and template-style patterns like {% %} and {{ }} |
crates/vim/src/normal.rs |
Adds test_percent_in_comment() test function that validates the new behavior against Neovim |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* main: (349 commits) component_preview: Fix license symlink (zed-industries#46379) Do not react on already observed buffer edits' versions (zed-industries#46308) Fix EP CLI output flicker (zed-industries#46313) vim: Fix bug where repeat operator could lead to unrecoverable replaying state (zed-industries#46376) vim: Implement text-based matching bracket logic for Vim '%' motion to correctly find pairs within comments (zed-industries#45559) Improve LSP button error message (zed-industries#46377) agent: Make reject/accept keybindings consistent with restore/stage (zed-industries#46373) Enable test-support features for some dev dependencies (zed-industries#46370) Capture terminal output when thread is interrupted (zed-industries#46306) Inline assistant tools: no more feature flag (zed-industries#46107) Add `ep split` subcommand for dataset splitting (zed-industries#46364) lsp_button: Fix long LSP version label (zed-industries#46359) remote: Introduce a proper mock remote connection (zed-industries#46337) ep: Allow matching patches against files without trailing newlines (zed-industries#46357) docs: Update "Custom Keybindings for Extension-Based Agents section" to include a troubleshooting note for defining an agent name (zed-industries#46144) Fail early if clangd is downloaded on aarch Linux (zed-industries#46346) ep: Handle errored requests in Anthropic batches (zed-industries#46351) settings_ui: Fix settings search missing results when BM25 finds partial matches (zed-industries#46349) workspace: Unpreview active tab when closing other tabs (zed-industries#46294) terminal: Skip SHLVL when loading login shell environment (zed-industries#46273) ...
|
This PR doesn't appear to work with |
Hey @hferreiro ! Thank you for reporting, I'll take a look at both, as I believe there's some overlap here and we can probably simplify. I believe the purpose of these changes was also to mimic Vim and NeoVim's behavior, where |
…o correctly find pairs within comments (zed-industries#45559) Closes zed-industries#25435 Release Notes: - Improved vim's '%' motion to always fall back to text-based bracket matching when language-aware matching fails
…o correctly find pairs within comments (zed-industries#45559) Closes zed-industries#25435 Release Notes: - Improved vim's '%' motion to always fall back to text-based bracket matching when language-aware matching fails
…o correctly find pairs within comments (zed-industries#45559) Closes zed-industries#25435 Release Notes: - Improved vim's '%' motion to always fall back to text-based bracket matching when language-aware matching fails
Closes #25435
Release Notes: