Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

cursor is misplaced on lsp_finder window #12

Open
DanielPower opened this issue Oct 5, 2021 · 11 comments
Open

cursor is misplaced on lsp_finder window #12

DanielPower opened this issue Oct 5, 2021 · 11 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@DanielPower
Copy link
Contributor

Description

When opening the references preview lua require'lspsaga.provider'.lsp_finder(), cursor and syntax highlighting is misaligned. See attached video.

Screen.Recording.2021-10-05.at.5.26.46.PM.mov

Expected Behavior
Cursor should align correctly with the file that's being previewed.

Actual Behavior
Cursor is always 3 lines above where it should be.

Neovim Built in Behavior
Neovim does not have this built-in. The built-in behaviour uses a quickfix list.

Details

Reproduce
  1. Attempt to use lua require'lspsaga.provider'.lsp_finder() on any symbol.
  2. Notice that the cursor is 3 lines higher than the item that's being previewed.
Environment
  • nvim --version output:
NVIM v0.5.1
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/build/config -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/build/src/nvim/auto -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/build/include
Compiled by brew@BigSur

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.5.1/share/nvim"

Run :checkhealth for more info
  • Operating system: MacOS 11.6.
  • lspsaga commit: 373bc03
@DanielPower DanielPower added the bug Something isn't working label Oct 5, 2021
@kkharji
Copy link
Owner

kkharji commented Oct 24, 2021

@DanielPower is it working on nvim51 branch without issues? I have some issue with the preview but cursor is placed correctly in nvim nightly

@DanielPower
Copy link
Contributor Author

Sorry for the late response. After switching from commit 276822b611b26be2e52a31d8eef1ccce30b819a5 to branch nvim51, this seems to have been resolved.

@bheadwhite
Copy link

@DanielPower @tami5 im still having this issue after specifying the nvim51 branch.

@DanielPower
Copy link
Contributor Author

So am I. sorry for the confusion. It doesn't happen every time and I wasn't able to reproduce it for a bit. Not sure what causes it to only happen sometimes.

@bheadwhite
Copy link

@DanielPower could we reopen this issue?

@DanielPower DanielPower reopened this Nov 15, 2021
@lancewl
Copy link

lancewl commented Nov 24, 2021

I'm also facing this issue as well with the newest neovim and lspsaga.nvim. Seems like the Definition part has been rendered twice so it breaks the UI.

@lancewl
Copy link

lancewl commented Dec 1, 2021

The problem resolved after I update the nvim-lspconfig today. Seems like is caused by the changes in nvim-lspconfig.

@DanielPower
Copy link
Contributor Author

I haven't seen it in a few days. It seems inconsistent. Not sure if it's been fixed since I updated to 0.6 and switched back to the master branch or not. If I don't see the issue again, and nobody responds to this issue that they're still having it on Neovim 0.6, then I'll close this issue in a week or so.

@DanielPower
Copy link
Contributor Author

DanielPower commented Dec 8, 2021

I've had the issue happen again on Neovim 0.6 with the latest version of lspsaga. So this does still exist.

Edit: Disregard. The computer I reproduced it on was still pointing at the nvim51 branch.

Edit 2: After updating and restarting, I'm still seeing the issue.

@kkharji kkharji added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 19, 2021
@Reicr
Copy link

Reicr commented Apr 1, 2022

Line 13 in lua/lspsaga/provider.lua

local def_response = lsp.buf_request_sync(0, method[1], def_params, timeout or 1000)

For some reason, the response includes an empty table as first entry.
Edit: A comment in another issue just gave me the hint, that each entry is the response of an attached language server on the buffer and the indexes are there ids. So I guess, it should always be assumed, that there can be more than one entry.

{
  [2] = {},
  [3] = {
    result = { {
        range = {
          end = {
            character = 19,
            line = 105
          },
          start = {
            character = 6,
            line = 105
          }
        },
        uri = "<cleared_out>"
      } }
  }
}

This causes libs.result_isempty to think the response is empty.

local responses = {}
  if libs.result_isempty(def_response) then
    def_response[1] = {}
    def_response[1].result = {}
    def_response[1].result.saga_msg = "0 definitions found"
  end
  table.insert(responses, def_response)

Since the first index([1]) is not set in def_response, it adds the block for no found entries at the beginning of the preview.
I changed libs.result_isempty to check all nested tables for a result entry before deciding it is empty.

function libs.result_isempty(res)
  if type(res) ~= "table" then
    print "[Lspsaga] Server return wrong response"
    return
  end
  for _, v in pairs(res) do
    if next(v) == nil then
      -- return true
      goto continue
    end
    if not v.result then
      -- return true
      goto continue
    end
    if next(v.result) == nil then
      -- return false 
      goto continue
    end
    if next(v.result) ~= nil then
      return false 
    end
    ::continue::
  end
  return true
end

This fixed the problem for me. Since I'm not very familiar with Lua, I'm not sure this is the best way to solve it. Some input would be appreciated.

@niuiic
Copy link

niuiic commented Jun 4, 2022

Same problem occurs on neovim 0.8 with the latest lspsaga. This problem will definitely appear when writing ts/js files, but not other filetypes. I tried other branchs, but it still exists.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants