ray-x / lsp_signature.nvim

LSP signature hint as you type
Apache License 2.0
2.01k stars 56 forks source link

How can I manually toggle lsp_signature #256

Closed aliawan01 closed 1 year ago

aliawan01 commented 1 year ago

I want to be able to toggle the appearance of the lsp_signature window with the keybinding Ctrl+Shift+space, I don't want the window to appear by default unless I press that keybinding.

ray-x commented 1 year ago

you can disable the floating windows and enable toggle key

 floating_window = false,
 toggle_key = '<M-x>' 
aliawan01 commented 1 year ago

Is there a way I can toggle the window's appearance with Ctrl+Shift+space, for some reason when I set `toggle_key = '', Ctrl+Shift+space still won't toggle the appearance of the signature window.

ray-x commented 1 year ago

not sure I understand your requirement. Could you send your minium vimrc?

https://user-images.githubusercontent.com/1681295/216440983-a4e71099-f706-480f-a2a2-c6fea297b83e.mp4

aliawan01 commented 1 year ago

This is the current way I have setup my lsp_signature (basically copied the example from the readme 😅):

 cfg = {
  verbose = false, -- show debug line number
  bind = true, -- This is mandatory, otherwise border config won't get registered.
               -- If you want to hook lspsaga or other signature handler, pls set to false
  doc_lines = 10, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated);
                 -- set to 0 if you DO NOT want any API comments be shown
                 -- This setting only take effect in insert mode, it does not affect signature help in normal
                 -- mode, 10 by default

  max_height = 12, -- max height of signature floating_window
  max_width = 80, -- max_width of signature floating_window
  noice = false, -- set to true if you using noice to render markdown
  wrap = true, -- allow doc/signature text wrap inside floating_window, useful if your lsp return doc/sig is too long

  floating_window = false, -- show hint in a floating window, set to false for virtual text only mode

  floating_window_above_cur_line = true, -- try to place the floating above the current line when possible Note:
  -- will set to true when fully tested, set to false will use whichever side has more space
  -- this setting will be helpful if you do not want the PUM and floating win overlap

  floating_window_off_x = 1, -- adjust float windows x position.
  floating_window_off_y = 0, -- adjust float windows y position. e.g -2 move window up 2 lines; 2 move down 2 lines
                              -- can be either number or function, see examples

  close_timeout = 4000, -- close floating window after ms when laster parameter is entered
  fix_pos = false,  -- set to true, the floating window will not auto-close until finish all parameters
  hint_enable = false, -- virtual hint enable
  hint_prefix = "🐼 ",  -- Panda for parameter, NOTE: for the terminal not support emoji, might crash
  hint_scheme = "String",
  hi_parameter = "LspSignatureActiveParameter", -- how your parameter will be highlight
  handler_opts = {
    border = "rounded"   -- double, rounded, single, shadow, none, or a table of borders
  },

  always_trigger = false, -- sometime show signature on new line or in middle of parameter can be confusing, set it to false for #58

  auto_close_after = nil, -- autoclose signature float win after x sec, disabled if nil.
  extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
  zindex = 200, -- by default it will be on top of all floating windows, set to <= 50 send it to bottom

  padding = '', -- character to pad on left and right of signature can be ' ', or '|'  etc

  transparency = nil, -- disabled by default, allow floating win transparent value 1~100
  shadow_blend = 36, -- if you using shadow as border use this set the opacity
  shadow_guibg = 'Black', -- if you using shadow as border use this set the color e.g. 'Green' or '#121315'
  timer_interval = 200, -- default timer check interval set to lower value if you want to reduce latency
  toggle_key = '<C-S-space>',

  select_signature_key = nil, -- cycle to next signature, e.g. '<M-n>' function overloading
  move_cursor_key = nil, -- imap, use nvim_set_current_win to move cursor between current win and floating
}

require'lsp_signature'.setup(cfg)

for some reason when I press Ctrl+Shift+space it doesn't toggle the lsp_signature popup.

ray-x commented 1 year ago

what is the output of :imap <C-S-Space>

Also <C-S-Space> will only enable in insert and snippet-insert and x mode

aliawan01 commented 1 year ago

when I run :imap <C-S-Space> it prints out No mapping found, I forgot to mention that I am also using neovide, perhaps this could be causing the problem?

ray-x commented 1 year ago

In that case, in your lsp on_attach() function, you can add a buffer keymap e.g.

    vim.keymap.set({ 'i', 'v', 's' }, '<C-S-Space>', function()
      require('lsp_signature').toggle_float_win()
    end, { silent = true, noremap = true, buffer = bufnr, desc = 'toggle signature' })

Or for all opened buffers:

    vim.keymap.set({ 'i', 'v', 's' }, _LSP_SIG_CFG.toggle_key, function()
      require('lsp_signature').toggle_float_win()
    end, { silent = true, noremap = true,  desc = 'toggle signature' })
aliawan01 commented 1 year ago

I tried setting the keymaps you suggested in my on_attach function, however this did not solve the issue either. This is probably a problem with neovide and not with the plugin itself since neovide has some issues with recoginising modifier keys in keybindings. For now I've settled with using <C-2> to toggle the appearance of the signature floating window. Thanks for the help!