Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the tag stack for jump to definition #1218

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from

Conversation

iamcodemaker
Copy link

@iamcodemaker iamcodemaker commented Apr 30, 2021

When jumping to a definition, updating the tag stack would be a useful feature. This allows navigating between definitions independently of other code navigation (ctrl-o/ctrl-i based jumping). Popping the stack is done using ctrl-t and works the same as jumping works with a tags file generated by ctags. The logic follows this example.

Closes #517.

Considerations

  • do we need to check for the gettagstack and settagstack functions before attempting to use them? They are recent additions to vim.
  • this has not been tested with nvim (only vim8)
  • if there are multiple potential matches and a selection must be made, the tag stack will not be updated

@iamcodemaker iamcodemaker marked this pull request as ready for review April 30, 2021 07:15
src/vim.rs Show resolved Hide resolved
@martskins
Copy link
Collaborator

I'm a little confused, I was expecting this to enable both :tag and :pop to work, and while I seem to be able to jump back in the tag stack using :pop I don't seem to be able to use :tag to go forwards in the tag stack. Isn't that how it's supposed to work? (genuinely asking, not 100% sure about how this works)

@iamcodemaker
Copy link
Author

iamcodemaker commented May 6, 2021

@martskins I noticed that as well. I'm not sure why :tag doesn't work either.

Edit: one would think:tag would just walk up the tag stack, but it gives an error message saying the tag is not found. It may have something to do with how I'm setting the tag name. I might have to take a look at the vim source to see what's going on.

@iamcodemaker
Copy link
Author

Ok, I think I know what's happening. Effectively, this is a limitation (or bug) in the way the tag stack is implemented in vim. When the :tag command is run, vim doesn't just jump to the next tag on the stack, it attempts to find that tag again in the tag file. Since there is no tag file the tag not found message is returned.

The tag stack contains the name of a tag and where we jumped from to get to that tag, but it doesn't contain the location of the tag, only the tag name. So it seems the only way to actually jump to the next tag on the tag stack would be to locate that tag again. In the case of settagstack the actual jump is done elsewhere and the location of the tag is not know to the tag stack.

@martskins
Copy link
Collaborator

The tagstack does contain the buf number and the position though, I would have expect it to use that to jump to the next tag. I'll try poking around some other implementations of this to see how they behave, I think vim-go has support for tags, so that'll be my first target.

@iamcodemaker
Copy link
Author

The tagstack does contain the buf number and the position though

No, it doesn't. It only contains that info for where we jumped from (which could be anywhere). It stores the bufnum, matchnum, and tagname of the current tag, which is enough to look it up from the tags file, but there is no tags file if settagstack was used. That's how vim works at least (not sure about nvim).

@martskins
Copy link
Collaborator

Ooh ok, I misunderstood that part, yeah, I see now. Thanks for clarifying.

@dimbleby
Copy link
Contributor

dimbleby commented May 8, 2021

#917 was a previous try at this - with much the same defects. There's some relevant discussion in that MR.

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