lsp_signature.nvim
Show function signature when you type
-
This nvim plugin is made for completion plugins that do not support signature help. Need neovim-0.5+ and enable nvim-lsp.
-
Part of the code was ported from completion-nvim, which does have lots of cool features.
-
Fully asynchronous lsp buf request.
-
Virtual text available
Note: decorator = {"`", "`"} setup is deprecate
Golang with markdown
Highlight with "Search"
signature2.mov
Lua
The plugin also re-write the builtin lsp signature allow the parameter highlight
Using virtual text to show the next parameter
Virtual text only mode
(from @fdioguardi)
Multiple signatures
In case some of the languages allow function overload, the plugin will show all available signatures
Scroll in side signature window
If max_height is set in the config and content exceed max_height, you can scroll up and down in signature window to view the hiding content.
Install:
" dein
dein#add('ray-x/lsp_signature.nvim')
" plug
Plug 'ray-x/lsp_signature.nvim'
" Packer
use {
"ray-x/lsp_signature.nvim",
}
Attach the plugin
In your init.lua
Call on_attach() when the LSP client attaches to a buffer
e.g. gopls:
local golang_setup = {
on_attach = function(client, bufnr)
...
require "lsp_signature".on_attach() -- Note: add in lsp client on-attach
...
end,
...
}
require'lspconfig'.gopls.setup(golang_setup)
Alternatively, use setup function
require "lsp_signature".setup()
Configure
Floating window borders
If you have a recent enough build of Neovim, you can configure borders in the signature help floating window(Thanks @Gabriel Sanches for the PR):
local example_setup = {
on_attach = function(client, bufnr)
...
require "lsp_signature".on_attach({
bind = true, -- This is mandatory, otherwise border config won't get registered.
handler_opts = {
border = "single"
}
})
...
end,
...
}
Or:
require'lspconfig'.gopls.setup()
require "lsp_signature".setup({
bind = true, -- This is mandatory, otherwise border config won't get registered.
handler_opts = {
border = "single"
}
})
Full configuration
cfg = {
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 = 2, -- 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
floating_window = true, -- show hint in a floating window, set to false for virtual text only mode
fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
hint_enable = true, -- virtual hint enable
hint_prefix = "🐼 ", -- Panda for parameter
hint_scheme = "String",
use_lspsaga = false, -- set to true if you want to use lspsaga popup
hi_parameter = "Search", -- how your parameter will be highlight
max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down
-- to view the hiding contents
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
handler_opts = {
border = "shadow" -- double, single, shadow, none
},
extra_trigger_chars = {} -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
-- deprecate !!
-- decorator = {"`", "`"} -- this is no longer needed as nvim give me a handler and it allow me to highlight active parameter in floating_window
zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom
debug = false, -- set to true to enable debug logging
log_path = "debug_log_file_path", -- debug log path
}
require'lsp_signature'.on_attach(cfg)
Note: navigator.lua no longer support auto setup for lsp_signature as the setup options is getting more complicated now
Q&A:
Q: What is the default colorscheme in screenshot:
A: aurora
Q: I can not see border after enable border = "single"
A: Try another colorscheme (e.g. colorscheme aurora, or colorscheme luna). If issue persists, please submit an issue
Q: It is not working 😡
A: Here is some trouble shooting: ray-x#1
Q:I do not like the pop window background highlight, how to change it?
A: Redefine your NormalFloat
and FloatBorder
, esp if your colorscheme dose not define it.
Q: How to change parameter highlight
A: By default, the highlight is using "Search" defined in your colorscheme, you can either override "Search" or
define, e.g. use IncSearch
on_attach({ hi_parameter = "IncSearch"})
Q: I can not see 🐼 in virtual text
A: It is emoji, not nerdfont. Please check how to enable emoji for your terminal.