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

Can not scroll with lspsaga smart scroll #118

Open
sandangel opened this issue Jun 5, 2022 · 11 comments
Open

Can not scroll with lspsaga smart scroll #118

sandangel opened this issue Jun 5, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@sandangel
Copy link

sandangel commented Jun 5, 2022

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 sandangel added the bug Something isn't working label Jun 5, 2022
@kkharji
Copy link
Owner

kkharji commented Jun 5, 2022

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
Copy link
Author

sandangel commented Jun 5, 2022

@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
Copy link
Author

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
Copy link
Owner

kkharji commented Jun 5, 2022

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
Copy link
Author

sandangel commented Jun 5, 2022

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
Copy link
Owner

kkharji commented Jun 5, 2022

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
Copy link
Author

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

@kkharji
Copy link
Owner

kkharji commented Jun 5, 2022

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
Copy link
Author

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
Copy link
Owner

kkharji commented Jun 5, 2022

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
Copy link
Author

sandangel commented Jun 6, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants