ray-x / lsp_signature.nvim

LSP signature hint as you type
Apache License 2.0
2.08k stars 57 forks source link

Scrolling view and keymap #228

Open ray-x opened 2 years ago

ray-x commented 2 years ago
    @ray-x Hey. Thanks for this plugin :)

I really think this should be a feature that is there out of the box. Many times documentations cannot be seen because it is cut off. For example, this happens to almost all the nvim lua documentations: image

It is not hard to implement this feature. In fact, I have done something similar already:

local function escape_term_codes(str)
  return vim.api.nvim_replace_termcodes(str, true, false, true)
end

local function is_float_open(window_id)
  return window_id and window_id ~= 0 and vim.api.nvim_win_is_valid(window_id)
end

local function scroll_float(mapping)
  -- Using the global config of the lsp_signature plugin
  local window_id = _G._LSP_SIG_CFG.winnr

  if is_lsp_float_open(window_id) then
    vim.fn.win_execute(window_id, 'normal! ' .. mapping)
  end
end

local map = vim.keymap.set
local opts = { noremap = true, silent = true }
local scroll_up_mapping = escape_term_codes('<c-u>')
local scroll_down_mapping = escape_term_codes('<c-d>')
map('i', '<c-u>', function() scroll_float(scroll_up_mapping) end, opts)
map('i', '<c-d>', function() scroll_float(scroll_down_mapping) end, opts)

Also, there is no scrollbar in the signature help, which I think is crucial to have, in order to even know that there is any documentation below the currently visible area. Otherwise, one would not even notice that. Something similar to the pum scrollbar would be nice. Many plugins do such a thing, for example nvim-cmp shows the scrollbar both in the completion and documentation window: image One can scroll through the documentation window by using the nvim-cmp config:

  local map = require('cmp').mapping

  require('cmp').setup({
    mapping = map.preset.insert({
      ['<c-d>'] = map.scroll_docs(5),
      ['<c-u>'] = map.scroll_docs(-5),
    }),
  })

So please add this feature, it would be great! :)

_Originally posted by @DasOhmoff in https://github.com/ray-x/lsp_signature.nvim/issues/110#issuecomment-1295831482_

philolo1 commented 1 year ago

If anybody looks at this code, the correct code is:

local function escape_term_codes(str)
    return vim.api.nvim_replace_termcodes(str, true, false, true)
end

local function is_float_open(window_id)
    return window_id and window_id ~= 0 and vim.api.nvim_win_is_valid(window_id)
end

local function scroll_float(mapping)
    local win_id = _G._LSP_SIG_CFG.winnr;

    if is_float_open(win_id) then
        vim.fn.win_execute(win_id, ':normal! ' .. mapping)
    end
end

local scroll_up_mapping = escape_term_codes('<c-u>')
local scroll_down_mapping = escape_term_codes('<c-d>')
vim.keymap.set('i', '<c-u>', function() scroll_float(scroll_up_mapping) end, {})
vim.keymap.set('i', '<c-d>', function() scroll_float(scroll_down_mapping) end, {})

there were different names in is_lsp_float_open and is_float_open.