lspsaga.nvim icon indicating copy to clipboard operation
lspsaga.nvim copied to clipboard

Can not scroll with lspsaga smart scroll

Open sandangel opened this issue 2 years ago • 11 comments

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

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', '<cmd>Lspsaga diagnostic_jump_next<cr>', opts)
vim.keymap.set('n', ']d', '<cmd>Lspsaga diagnostic_jump_prev<cr>', opts)
vim.keymap.set('n', 'gl', '<cmd>Lspsaga show_line_diagnostics<cr>', opts)
vim.keymap.set('n', 'gL', '<cmd>lua vim.diagnostic.setloclist()<cr>', opts)
vim.keymap.set('n', 'gq', '<cmd>lua vim.diagnostic.setqflist()<cr>', 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', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
  vim.keymap.set('n', 'gd', '<cmd>Lspsaga preview_definition<cr>', opts)
  vim.keymap.set('n', 'gh', '<cmd>Lspsaga hover_doc<cr>', opts)
  vim.keymap.set('n', 'gi', '<cmd>Lspsaga implement<cr>', opts)
  vim.keymap.set('n', 'gk', '<cmd>Lspsaga signature_help<cr>', opts)
  vim.keymap.set('n', 'gr', '<cmd>Lspsaga rename<cr>', opts)
  vim.keymap.set('n', 'gR', '<cmd>Lspsaga lsp_finder<cr>', opts)
  vim.keymap.set('n', 'gA', '<cmd>Lspsaga code_action<cr>', opts)
  vim.keymap.set('x', 'gx', '<cmd>Lspsaga range_code_action<cr>', opts)
  vim.keymap.set('n', 'gf', '<cmd>lua vim.lsp.buf.format()<cr>', opts)
  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)
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

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 = '<esc>',
    scroll_down = '<c-f>',
    scroll_up = '<c-b>',
  },
  code_action_keys = {
    quit = '<esc>',
    exec = '<cr>',
  },
  rename_action_keys = {
    quit = '<esc>',
    exec = '<cr>',
  },
  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
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

sandangel avatar Jun 05 '22 13:06 sandangel

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

kkharji avatar Jun 05 '22 13:06 kkharji

@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 avatar Jun 05 '22 13:06 sandangel

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

sandangel avatar Jun 05 '22 13:06 sandangel

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

kkharji avatar Jun 05 '22 14:06 kkharji

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

sandangel avatar Jun 05 '22 14:06 sandangel

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.

kkharji avatar Jun 05 '22 15:06 kkharji

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

sandangel avatar Jun 05 '22 15:06 sandangel

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 @

kkharji avatar Jun 05 '22 16:06 kkharji

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.

sandangel avatar Jun 05 '22 16:06 sandangel

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.

kkharji avatar Jun 05 '22 19:06 kkharji

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

sandangel avatar Jun 06 '22 11:06 sandangel