Skip to content

Implement Vim's tag stack#46002

Merged
cameron1024 merged 2 commits intozed-industries:mainfrom
zenazn:carl-tag-stack-2
Jan 15, 2026
Merged

Implement Vim's tag stack#46002
cameron1024 merged 2 commits intozed-industries:mainfrom
zenazn:carl-tag-stack-2

Conversation

@zenazn
Copy link
Contributor

@zenazn zenazn commented Jan 4, 2026

Happy New Years! This PR is a second take at #38127 (cc @ConradIrwin)

This PR is significantly less complicated than the last attempt: while we still keep our data on the NavigationHistory object, we no longer tightly integrate it with the existing back/forward "browser history." Instead, we keep our own stack of (origin, target) pairs (in a struct to make it easy to extend with e.g., tag names in the future).

The PR is split into two separable commits. Most of the implementation is in the second commit, which:

  • Defines the stack data structure
  • Implements pane::GoToOlderTag and pane::GoToNewerTag in terms of the stack
  • Hooks into navigate_to_hover_links to push tag stack entries

This last bit is the most fiddly. The core challenge is that we need to keep track of the origin location and calculate the target location across three codepaths that might involve creating a new editor and/or splitting the pane. One thing in particular I found difficult was that an editor's nav_history (an ItemNavHistory) seems to be populated asynchronously. Instead of relying on it, I decided in this code to make my own ItemNavHistory. I briefly tried to refactor the code in question, but it seemed like it would significantly increase the scope of the change.

I prefer this all-in-one tracking centered around navigate_to_hover_links to the start/finish approach taken in b69a2ea because I find it easier to convince myself that the right data is being populated at the right times. Of course, let me know if you think there's a better solution.

Closes #14206

Release Notes:

  • ??? I don't know what to write here! Suggestions welcome

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 4, 2026
@cameron1024 cameron1024 self-assigned this Jan 5, 2026
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Jan 6, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against a44bebc

Copy link
Contributor

@cameron1024 cameron1024 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, code looks good 😁

@cameron1024
Copy link
Contributor

Ooh actually that test failure seems important, taking a look

@zenazn
Copy link
Contributor Author

zenazn commented Jan 6, 2026

The first commit changes the semantics of splitting panes to also fork nav history. That appears to be upsetting some of the assumptions the test_preview_tabs test makes. Let me fix that up, and fix up the merge conflicts as well. Please hold!

zenazn added 2 commits January 6, 2026 11:09
This change is hopefully mildly useful for everyone (you can now use
splits to "explore" history without risking giving up on your current
state), and will be very helpful in a few moments for implementing the
Vim tag stack
Implement a Vim-like tag stack for Zed. We keep an extra stack of
`(origin, target)` pairs in navigation history. Every go-to-definition
(and similar, e.g., ctrl-clicking an identifier) pushes an entry onto
the tag stack with the origin and target of the jump. You can navigate
to older and newer tag stack entries using the new commands
`pane::GoToOlderTag` and `pane::GoToNewerTag`. This is especially
helpful for exploring codebases: it makes it easy to drill down into an
unfamiliar function, then to quickly get back to where you were, without
hammering the "back" button in the editor.

While efforts have been made to make Vim users feel at home, there's
nothing Vim-specific about the feature. Hopefully others find it helpful
too!
@zenazn
Copy link
Contributor Author

zenazn commented Jan 6, 2026

@cameron1024 alright, ready for another look! Test fix is in the first commit

@zenazn
Copy link
Contributor Author

zenazn commented Jan 12, 2026

@cameron1024 is there anything I can do to help move this PR along?

@cameron1024
Copy link
Contributor

Apologies, got distracted with other things and haven't looked at this test. If you think you can take a look at it, go for it and ping me when you want another review :)

@zenazn
Copy link
Contributor Author

zenazn commented Jan 12, 2026

I already fixed that test failure. Could you re-run the test suite?

@zenazn
Copy link
Contributor Author

zenazn commented Jan 13, 2026

@cameron1024 looks like the tests passed. I'd appreciate it if you had another look!

@cameron1024
Copy link
Contributor

Looks great, thanks for implementing this 🙏

@cameron1024 cameron1024 merged commit 1ded60a into zed-industries:main Jan 15, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emulate the tag stack in Vim mode

3 participants