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

vim.lsp.buf.definition() adds extra entry to jumplist when definition file not opened yet #28784

Closed
mikehaertl opened this issue May 16, 2024 · 4 comments

Comments

@mikehaertl
Copy link

mikehaertl commented May 16, 2024

Problem

When vim.lsp.buf.definition() is called and the file with the definition is not yet available in a buffer I find an extra entry in the jumplist. It points to the top of the file that contains the definition.

Steps to reproduce

  1. Open any file with references to a definition in another file.
  2. Make sure the other file is not opened in a buffer.
  3. call :lua vim.lsp.buf.definition()

Expected behavior

The jumplist should only have one entry. So a single <C-O> should take you back to where you called vim.lsp.buf.definition().

Instead the first <c-o> takes me to the top of the definition file and I need a second <c-o> to get back to the initial location.

Neovim version (nvim -v)

0.10.0

Vim (not Nvim) behaves the same?

Operating system/version

Linux Mint 21.3

Terminal name/version

Gnome Terminal 3.44.0

$TERM environment variable

screen-256-color

Installation

build from repo

@mikehaertl mikehaertl added the bug issues reporting wrong behavior label May 16, 2024
@github-actions github-actions bot added the lsp label May 16, 2024
@mikehaertl mikehaertl changed the title vim.lsp.buf.definition() adds two entries to the jumplist when definition file not opened yet vim.lsp.buf.definition() adds extra entry to jumplist when definition file not opened yet May 16, 2024
@icholy
Copy link
Contributor

icholy commented May 27, 2024

I'm not able to reproduce this with gopls:
no-extra-jump

@justinmk justinmk added this to the backlog milestone May 28, 2024
@mikehaertl
Copy link
Author

I will investigate further and try to provide a minimal config to reproduce the issue.

@icholy
Copy link
Contributor

icholy commented May 28, 2024

@mikehaertl btw I was testing on nightly, not 0.10.0

I cannot reproduce with nightly or 0.10.0.

@wookayin wookayin added the needs:repro We need minimal steps to reproduce the issue label May 30, 2024
@mikehaertl
Copy link
Author

mikehaertl commented May 30, 2024

Issue was actually caused by this little config that I've probably copied from somewhere a long time ago and never reconsidered:

" When editing a file, always jump to the last cursor position.
autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif

The fix was easy: use g`" instead of `"

autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal! g`\"" | endif

Source: https://stackoverflow.com/a/774599

EDIT: Even better: :help last-position-jump

@zeertzjq zeertzjq removed bug issues reporting wrong behavior needs:repro We need minimal steps to reproduce the issue lsp jumps-navigation labels May 30, 2024
@zeertzjq zeertzjq removed this from the backlog milestone May 30, 2024
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

No branches or pull requests

5 participants