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

fix: unable get expected altbuf #501

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

fengwk
Copy link
Contributor

@fengwk fengwk commented Jun 5, 2023

In commit 365811e, we inferred the altbuf. However, there are two issues:

  1. bufnr([{buf} [, {create}]]) - The second parameter 'create' in bufnr([{buf} [, {create}]]) cannot be set to a value, as it will create a new buffer when no previous buffer exists.
  2. When I execute lsp_util.locations_to_items in the jdt:// buffer, other jdt:// locations will be parsed. However, at this point, I cannot retrieve the previous buffer using bufnr('#'). The return value will be -1.

Therefore, I want to manage the latest accessed buffer associated with jdtls. I will record the latest buffer at on_attach and BufEnter.

Copy link
Owner

@mfussenegger mfussenegger left a comment

Choose a reason for hiding this comment

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

Can you explain how you produce the issue?

This looks pretty complex

@fengwk
Copy link
Contributor Author

fengwk commented Jun 23, 2023

This happens when two jdtls LSPs are opened simultaneously, and the following steps may be able to reproduce this situation:

  1. First, open a file from Project A, which initiates the LSP for Project A.
  2. Open a file from Project B, which initiates the LSP for Project B.
  3. Navigate from the open position in Project B to a source file that is not in the current project, which will load this file into the LSP for Project B via the jdt:// protocol.
  4. Then, use jump_to_location in the position of Project B to jump again, for instance, by executing vim.lsp.buf.definition to navigate to another source file that is not in the current project. This will also load the file via the jdt:// protocol. At this point, obtaining altbuf becomes invalid, leading to incorrect binding of the LSP.

As I do not fully understand the internal implementation mechanism of vim.lsp, I have thought of a compromise solution where I can manage the LSP file of the most recent plan myself to avoid this case.

@fengwk
Copy link
Contributor Author

fengwk commented Jun 23, 2023

I need to further elaborate on the impact of this issue. If the LSP of Project A does not have the corresponding file, the jump will fail. In my case, both Projects A and B rely on the same version, but the LSP loaded the wrong version. As a result, I discovered the issue of incorrectly binding the buffer to the LSP.

@fengwk
Copy link
Contributor Author

fengwk commented Jun 23, 2023

Another reason for the commit "fix: modify the method of obtaining ft to respond to bad cases" is that I noticed that sometimes vim.bo[bufnr].filetype == "java" doesn't work as expected, but vim.api.nvim_buf_get_option(bufnr, "filetype") always returns the desired result.

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.

2 participants