kkharji / archive-323

The neovim language-server-client UI
MIT License
408 stars 43 forks source link

Can not scroll with lspsaga smart scroll #118

Open sandangel opened 2 years ago

sandangel commented 2 years ago

Description

Hi, I got this error when trying to execute keymap for lspsaga smart scroll

E5108: Error executing lua ...te/pack/packer/start/lspsaga.nvim/lua/lspsaga/action.lua:30: attempt to compare nil with number
stack traceback:
        ...te/pack/packer/start/lspsaga.nvim/lua/lspsaga/action.lua:30: in function 'scroll_in_win'
        .../pack/packer/start/lspsaga.nvim/lua/lspsaga/provider.lua:423: in function 'scroll_in_preview'
        .../pack/packer/start/lspsaga.nvim/lua/lspsaga/provider.lua:481: in function 'scroll_in_preview'
        [string ":lua"]:1: in main chunk

Expected Behavior

It should scroll the window up/down

Actual Behavior

It showed the error above

Neovim Built in Behavior

Neovim doesn't have this built in AFAIK

Details

Reproduce lspconfig.lua ```lua local root_pattern = require('lspconfig.util').root_pattern local lspconfig = require 'lspconfig' local capabilities = require('plugins.configs.cmp').capabilities vim.lsp.set_log_level 'error' vim.diagnostic.config { virtual_text = { prefix = '', }, signs = true, underline = true, update_in_insert = false, } local opts = { silent = true } vim.keymap.set('n', '[d', 'Lspsaga diagnostic_jump_next', opts) vim.keymap.set('n', ']d', 'Lspsaga diagnostic_jump_prev', opts) vim.keymap.set('n', 'gl', 'Lspsaga show_line_diagnostics', opts) vim.keymap.set('n', 'gL', 'lua vim.diagnostic.setloclist()', opts) vim.keymap.set('n', 'gq', 'lua vim.diagnostic.setqflist()', opts) vim.api.nvim_create_augroup('LSPConfigUser', { clear = true }) local on_attach = function(client, bufnr) if client.name == 'sumneko_lua' or client.name == 'gopls' then vim.api.nvim_create_autocmd('BufWritePre', { group = 'LSPConfigUser', buffer = bufnr, callback = function() vim.lsp.buf.format() end, }) end -- Mappings. opts.buffer = bufnr -- See `:help vim.lsp.*` for documentation on any of the below functions vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) vim.keymap.set('n', 'gd', 'Lspsaga preview_definition', opts) vim.keymap.set('n', 'gh', 'Lspsaga hover_doc', opts) vim.keymap.set('n', 'gi', 'Lspsaga implement', opts) vim.keymap.set('n', 'gk', 'Lspsaga signature_help', opts) vim.keymap.set('n', 'gr', 'Lspsaga rename', opts) vim.keymap.set('n', 'gR', 'Lspsaga lsp_finder', opts) vim.keymap.set('n', 'gA', 'Lspsaga code_action', opts) vim.keymap.set('x', 'gx', 'Lspsaga range_code_action', opts) vim.keymap.set('n', 'gf', 'lua vim.lsp.buf.format()', opts) vim.keymap.set('n', '', "lua require('lspsaga.action').smart_scroll_with_saga(1, '')", opts) vim.keymap.set('n', '', "lua require('lspsaga.action').smart_scroll_with_saga(-1, '')", opts) end local runtime_path = vim.split(package.path, ';') table.insert(runtime_path, 'lua/?.lua') table.insert(runtime_path, 'lua/?/init.lua') lspconfig.sumneko_lua.setup { on_attach = on_attach, capabilities = capabilities, settings = { Lua = { runtime = { version = 'LuaJIT', path = runtime_path, }, diagnostics = { enable = true, globals = { 'vim' }, neededFileStatus = { ['codestyle-check'] = 'Any', }, }, workspace = { library = vim.api.nvim_get_runtime_file('', true), }, telemetry = { enable = false, }, format = { enable = true, defaultConfig = { indent_style = 'space', indent_size = '2', quote_style = 'single', call_arg_parentheses = 'unambiguous_remove_string_only', }, }, }, }, } ``` lspsaga.lua ```lua local lspsaga = require 'lspsaga' lspsaga.setup { debug = true, use_saga_diagnostic_sign = false, -- diagnostic sign error_sign = '', warn_sign = '', hint_sign = '', infor_sign = '', diagnostic_header_icon = '  ', -- code action title icon code_action_icon = ' ', code_action_prompt = { enable = true, sign = true, sign_priority = 40, virtual_text = true, }, finder_definition_icon = ' ', finder_reference_icon = ' ', max_preview_lines = 10, finder_action_keys = { open = 'o', vsplit = 's', split = 'i', quit = '', scroll_down = '', scroll_up = '', }, code_action_keys = { quit = '', exec = '', }, rename_action_keys = { quit = '', exec = '', }, definition_preview_icon = ' ', border_style = 'single', rename_prompt_prefix = '➤', rename_output_qflist = { enable = false, auto_open_qflist = false, }, server_filetype_map = {}, diagnostic_prefix_format = '%d. ', diagnostic_message_format = '%m %c', highlight_prefix = false, } ```
Environment ```sh NVIM v0.8.0-dev Build type: Release LuaJIT 2.1.0-beta3 Compiled by nixbld Features: +acl +iconv +tui See ":help feature-compile" system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: " /nix/store/rvillp8grvwp6cx1qkwayd4x3jwwsgf2-neovim-unwrapped-master/share/nvim " Run :checkhealth for more info ``` Linux NixOS 22.05
kkharji commented 2 years ago

hmmm can you share how you've bind it.

    require'lspsaga.action'.smart_scroll_with_saga(1, '<c-d>')
    require'lspsaga.action'.smart_scroll_with_saga(-1, '<c-u>')

works for me

sandangel commented 2 years ago

@tami5 sorry my lspconfig was a bit long, the binding is included in the issue description, but I will put it here:

local opts = { silent = true, buffer = bufnr }
vim.keymap.set('n', '<c-f>', "<cmd>lua require('lspsaga.action').smart_scroll_with_saga(1, '<c-f>')<cr>", opts)
vim.keymap.set('n', '<c-b>', "<cmd>lua require('lspsaga.action').smart_scroll_with_saga(-1, '<c-b>')<cr>", opts)
sandangel commented 2 years ago

this is what I have when running :verbose map <c-f>

n  <C-F>       *@<Cmd>lua require('lspsaga.action').smart_scroll_with_saga(1, '<C-F>')<CR>
        Last set from Lua
kkharji commented 2 years ago

hmmm thats odd, the issue is here

    if current_win_lnum >= last_lnum then
      current_win_lnum = last_lnum - 1
    end

so this function scroll_in_win is called by multiple provider, does this happen when you want to scroll hover?, some how last_num isn't set by the caller, which can be a bug

sandangel commented 2 years ago

Hi @tami5 , thanks for taking a look. the smart scroll does not work in all lspsaga windows (hover, preview definition...) (nothing happens), but only the scroll in lsp finder generate the error

kkharji commented 2 years ago

but only the scroll in lsp finder generate the error

Oh, I see, I was wondering why I didn't experience this error. unfortunately this is the one thing I kept but haven't been using, there are many open issues regarding lsp finder and I recommend replacing with something like telescope lsp_* . feel free to continue debugging if you found a solution please open a pr.

sandangel commented 2 years ago

@tami5 but the normal smart scroll command do not work on other lspsaga windows too. (hover, preview definition) 😭

kkharji commented 2 years ago

hmmm

this is what I have when running :verbose map <c-f>

n  <C-F>       *@<Cmd>lua require('lspsaga.action').smart_scroll_with_saga(1, '<C-F>')<CR>
        Last set from Lua

Maybe the way the command is set?

n  <C-D>       * <Cmd>lua require'lspsaga.action'.smart_scroll_with_saga(1, '<C-D>')<CR>
        Last set from Lua

mine doesn't have @

sandangel commented 2 years ago

it's because i set them in with buffer option. I also set them without buffer option but it doesn't work. Is there a way to jump to the lspsaga window? I can scroll from there. I tried with <C-w>W or <C-w><C-w> but the window only closes.

kkharji commented 2 years ago

it's because i set them in with buffer option. I also set them without buffer option but it doesn't work. Is there a way to jump to the lspsaga window? I can scroll from there. I tried with <C-w>W or <C-w><C-w> but the window only closes.

I'm also setting it using buffer, try using old vim api vim.cmd'nmap <buffer>...'

for hovers you can double hover to jump to it, others not sure.

sandangel commented 2 years ago

for hovers you can double hover to jump to it, others not sure.

hi @tami5 , can we make it work the same for other windows? like jumping to the window that we need to scroll when we hit the keymap again when that window is opened?

I tried with old vim api but it also didn't work