Closed gegoune closed 3 years ago
Thanks for trying this out.
Did a quick test with lua and python. It should work
Can you check if your 'textDocument/hover' or 'lua vim.lsp.buf.signature_help()' works when the cursor inside bracket?
Sometime when lsp can not find signature, pop up will not show. This may happen for the script where function definition is not strong typed.
my lua lsp config is here: https://github.com/ray-x/dotfiles/blob/7e7709cdab3491e03a6f7fd5f96d13ac139cd865/lua/lsp_config.lua#L383
Yes, calling lua vim.lsp.buf.signature_help()
does show signature help, so it's there and working, just doesn't show up automatically. Perhaps some autocmd is missing?
That is a bit wired.
require "lsp_signature".on_attach()
Should register the handler to Insert event.
One more thing to check:
I also exported the signature function, can you check if
lua require'lsp_signature'.signature()
give you same result of:
lua vim.lsp.buf.signature_help()
If it shows the same, that means the handler was not registered. If signature() also shows nothing, that there are other place need to check. So another thing to check is
require "lsp_signature".on_attach()
lua require'lsp_signature'.signature()
Togher to enforce on_attach to run again. I put my attach() in init.lua. Not sure it works same way in parker.
Interesting, lua require'lsp_signature'.signature()
returned nothing in both tests, that is, with and without (after) require "lsp_signature".on_attach()
.
Did double check and lua vim.lsp.buf.signature_help()
showed signature.
Thanks for helping with debug!
I just full back to a min config. It still works.
call plug#begin('~/.vim/plugged')
" Group dependencies, vim-snippets depends on ultisnips
Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/lsp_signature.nvim'
call plug#end()
lua <<EOF
local nvim_lsp = require('lspconfig')
-- require('lsp_config') -- you may need my lsp_config.lua
require('lsp_signature').on_attach()
local sumneko_root_path = vim.fn.expand("$HOME")..'/github/sumneko/lua-language-server'
local sumneko_binary = vim.fn.expand("$HOME")..'/github/sumneko/lua-language-server/bin/macOS/lua-language-server'
local on_attach = function(client, bufnr)
require'lsp_signature'.on_attach()
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
end
require'lspconfig'.sumneko_lua.setup {
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"};
on_attach = on_attach,
}
EOF
Can you send a minimum vimrc to reproduce the issue. I tried packer a few months before, but does not keep the configurations.
Also tried following pack config vimrc it works as expected.
lua <<EOF
vim.cmd [[packadd packer.nvim]]
-- Only if your version of Neovim doesn't have https://github.com/neovim/neovim/pull/12632 merged
-- vim._update_package_paths()
require('packer').startup(function()
use {
"neovim/nvim-lspconfig",
"ray-x/lsp_signature.nvim",
}
end)
local nvim_lsp = require('lspconfig')
-- require('lsp_config') -- you may need my lsp_config.lua
require('lsp_signature').on_attach()
local sumneko_root_path = vim.fn.expand("$HOME")..'/github/sumneko/lua-language-server'
local sumneko_binary = vim.fn.expand("$HOME")..'/github/sumneko/lua-language-server/bin/macOS/lua-language-server'
local on_attach = function(client, bufnr)
require'lsp_signature'.on_attach()
end
require'lspconfig'.sumneko_lua.setup {
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"};
on_attach = on_attach,
}
EOF
let g:min_load = 1 "prevent other configure to load
It works with minimal config, so something else in my configuration conflicts with your plugin. Will try to figure it out and come back to you. Thanks!
It cut my configuration in many different ways, removed all plugins, settings and whatever else I could think of, but still no luck. Do you have any insight where to look exactly, as in, what could be stopping your plugin from working?
It is really wired. Can you check if my minimum vimrc works for you or not? Also, I am using kitty + mac. Your issue looks like the event was hijacked and was not hooked. Another thing is timer. The code setup time in this plugin
timer:start(100, 200, vim.schedule_wrap(function()
...
This setup works for me. delay 100ms and refresh every 200ms.
And my timeout setting in vimrc: timeoutlen = 500; ttimeoutlen = 10; updatetime = 100; redrawtime = 1500;
The final check is to dump all InsertEnter/Leave registration in vim... That would be annoying to check the conflictions.
Also tried following pack config vimrc it works as expected.
lua <<EOF vim.cmd [[packadd packer.nvim]] -- Only if your version of Neovim doesn't have https://github.com/neovim/neovim/pull/12632 merged -- vim._update_package_paths() require('packer').startup(function() use { "neovim/nvim-lspconfig", "ray-x/lsp_signature.nvim", } end) local nvim_lsp = require('lspconfig') -- require('lsp_config') -- you may need my lsp_config.lua require('lsp_signature').on_attach() local sumneko_root_path = vim.fn.expand("$HOME")..'/github/sumneko/lua-language-server' local sumneko_binary = vim.fn.expand("$HOME")..'/github/sumneko/lua-language-server/bin/macOS/lua-language-server' local on_attach = function(client, bufnr) require'lsp_signature'.on_attach() end require'lspconfig'.sumneko_lua.setup { cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}; on_attach = on_attach, } EOF let g:min_load = 1 "prevent other configure to load
Ah, no, problem definitely is within my configuration. Your minimal configuration with packer does work.
I am not sure if it is due to autocmd or not, but lua require'lsp_signature'.signature()
returns nil
when run on pcall(|
(where |
is cursor).
Is your plugin is lazyloading? Try opt=false?
No, it's not lazy loaded:
use {
"neovim/nvim-lspconfig",
requires = {
{
"kosayoda/nvim-lightbulb",
config = function()
vim.api.nvim_command("highlight LightBulbVirtualText guifg=red")
end
},
"nvim-lua/lsp-status.nvim",
{"ojroques/nvim-lspfuzzy", config = require "lspfuzzy".setup {}},
"ray-x/lsp_signature.nvim"
}
}
I then have require "lsp"
in my init.lua
sourcing lsp/init.lua
with require "lsp_signature".on_attach()
in custom on_attach()
function which is called by every language server I have set up.
Hi, @cloggier Can you send me your minium vimrc, hopefully, 1 or 2 files so I can reproduce your issue?
Does not work for me also. Is it because I use compe
?
I may add this info - language server seems to provide this functionality.
use {'neovim/nvim-lspconfig'}
require'lspconfig'.intelephense.setup{
on_attach = function(client, bufnr)
print(vim.inspect(client.resolved_capabilities))
end
}
Outputs:
{
call_hierarchy = false,
code_action = false,
code_lens = false,
code_lens_resolve = false,
completion = true,
declaration = false,
document_formatting = true,
document_highlight = true,
document_range_formatting = true,
document_symbol = true,
execute_command = false,
find_references = true,
goto_definition = true,
hover = true,
implementation = false,
rename = false,
signature_help = true,
signature_help_trigger_characters = { "(", "," },
text_document_did_change = 2,
text_document_open_close = true,
text_document_save = true,
text_document_save_include_text = false,
text_document_will_save = false,
text_document_will_save_wait_until = false,
type_definition = false,
workspace_folder_properties = {
changeNotifications = true,
supported = true
},
workspace_symbol = true
}
Hi.
Tried with pyright
and pyls
; both give me
Error executing vim.schedule lua callback: ...einthesky/.local/share/nvim/runtime/lua/vim/lsp/util.lua:946: Failed to switch to window 1006
when open the bracket.
This is my config;
local on_attach = function(client, _)
require "completion".on_attach(client)
require "lsp_signature".on_attach(client)
utils.opt("omnifunc", "v:lua.vim.lsp.omnifunc")
local lsp_keymappings = {
{"n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>"},
{"n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>"},
{"n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>"},
{"n", "<leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>"},
{"n", "<leader>td", "<cmd>lua vim.lsp.buf.type_definition()<CR>"},
{"n", "<leader>rf", "<cmd>lua vim.lsp.buf.references()<CR>"},
{"n", "<leader>ll", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>"},
-- Use <Tab> and <S-Tab> to navigate through popup menu
{"i", "<Tab>", 'pumvisible() ? "\\<C-n>" : "\\<Tab>"', {expr = true}},
{"i", "<S-Tab>", 'pumvisible() ? "\\<C-p>" : "\\<Tab>"', {expr = true}}
}
for _, map in ipairs(lsp_keymappings) do
local mode, lhs, rhs, opts = unpack(map)
utils.map(mode, lhs, rhs, opts)
end
-- Format on save
if client.resolved_capabilities.document_formatting then
vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting()]]
end
-- Document highlight
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec(
[[
hi LspReferenceRead cterm=bold ctermbg=239 guibg=#504945
hi LspReferenceText cterm=bold ctermbg=239 guibg=#504945
hi LspReferenceWrite cterm=bold ctermbg=243 guibg=#7c6f64
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
false
)
end
end
lspconfig.pyright.setup {
on_attach = on_attach
}
I may add this info - language server seems to provide this functionality.
use {'neovim/nvim-lspconfig'} require'lspconfig'.intelephense.setup{ on_attach = function(client, bufnr) print(vim.inspect(client.resolved_capabilities)) end }
Outputs:
{ call_hierarchy = false, code_action = false, code_lens = false, code_lens_resolve = false, completion = true, declaration = false, document_formatting = true, document_highlight = true, document_range_formatting = true, document_symbol = true, execute_command = false, find_references = true, goto_definition = true, hover = true, implementation = false, rename = false, signature_help = true, signature_help_trigger_characters = { "(", "," }, text_document_did_change = 2, text_document_open_close = true, text_document_save = true, text_document_save_include_text = false, text_document_will_save = false, text_document_will_save_wait_until = false, type_definition = false, workspace_folder_properties = { changeNotifications = true, supported = true }, workspace_symbol = true }
@talbergs In fact, I could not reproduce the issue. Here is my PHP lsp setup with compe
lua <<EOF
vim.cmd [[packadd packer.nvim]]
require('packer').startup(function()
use {
"wbthomason/packer.nvim",
"neovim/nvim-lspconfig",
"hrsh7th/nvim-compe",
"ray-x/lsp_signature.nvim"
}
end)
local lspconfig = require('lspconfig')
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = true;
source = {
nvim_lsp = true;
vsnip = true;
};
}
require "lsp_signature".on_attach()
require('lspconfig').intelephense.setup{
}
EOF
let g:min_load = 1
One thing, writeMsg() does not have a signature as there ar no arguments .
Hi. Tried with
pyright
andpyls
; both give meError executing vim.schedule lua callback: ...einthesky/.local/share/nvim/runtime/lua/vim/lsp/util.lua:946: Failed to switch to window 1006
when open the bracket.
This is my config;
local on_attach = function(client, _) require "completion".on_attach(client) require "lsp_signature".on_attach(client) utils.opt("omnifunc", "v:lua.vim.lsp.omnifunc") local lsp_keymappings = { {"n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>"}, {"n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>"}, {"n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>"}, {"n", "<leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>"}, {"n", "<leader>td", "<cmd>lua vim.lsp.buf.type_definition()<CR>"}, {"n", "<leader>rf", "<cmd>lua vim.lsp.buf.references()<CR>"}, {"n", "<leader>ll", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>"}, -- Use <Tab> and <S-Tab> to navigate through popup menu {"i", "<Tab>", 'pumvisible() ? "\\<C-n>" : "\\<Tab>"', {expr = true}}, {"i", "<S-Tab>", 'pumvisible() ? "\\<C-p>" : "\\<Tab>"', {expr = true}} } for _, map in ipairs(lsp_keymappings) do local mode, lhs, rhs, opts = unpack(map) utils.map(mode, lhs, rhs, opts) end -- Format on save if client.resolved_capabilities.document_formatting then vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting()]] end -- Document highlight if client.resolved_capabilities.document_highlight then vim.api.nvim_exec( [[ hi LspReferenceRead cterm=bold ctermbg=239 guibg=#504945 hi LspReferenceText cterm=bold ctermbg=239 guibg=#504945 hi LspReferenceWrite cterm=bold ctermbg=243 guibg=#7c6f64 augroup lsp_document_highlight autocmd! * <buffer> autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() augroup END ]], false ) end end lspconfig.pyright.setup { on_attach = on_attach }
@horseinthesky Should be fixed in the new version. Thanks for reporting.
Thank you @ray-x ! This is the change I had to do, to get this plugin working.
use {'ray-x/lsp_signature.nvim',
config = function()
- require "lsp_signature".on_attach()
end
}
+require "lsp_signature".on_attach()
That still does not solve the issue for me though, I am calling that function from my custom on_attach function from lsp initialisation.
Thanks for the feedback. I think the packer lazy loading might prevent the on_attach be called. And as @cloggier suggested. attach the plugin in lsp client attach func would do the trick
local golang_setup = {
on_attach = function(client, bufnr)
if lsp_status ~= nil then
lsp_status.on_attach(client, bufnr)
end
require "lsp_signature".on_attach() -- Note: add in lsp client on-attach
diagnostic_map(bufnr),
...
end,
...
}
I updated the README.md as well
@ray-x Apologies if I wasn't clear enough. It does not work for me still, even with require "lsp_signature".on_attach()
in on_attach
function.
In that case, I will leave the issue open ATM and I will wait on more info regarding how to reproduce the issue.
Here is a minimum config that does not work for me:
call plug#begin('~/.config/nvim/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/lsp_signature.nvim'
call plug#end()
lua require'lspconfig'.tsserver.setup{}
lua require'lsp_signature'.on_attach()
Although running :lua vim.lsp.buf.signature_help()
and :lua require'lsp_signature'.signature()
commands manually, shows the signature help pop up.
Neovim info:
NVIM v0.5.0-dev+f89bfa686
Build type: Release
LuaJIT 2.1.0-beta3
@milad-abbasi
Can not reproduce.
I am suspect if the lsp server started or not in your case.
The default tsserver require package.json
or a tsconfig.json
in your project root, otherwise it will not start and thus the signature will not work.
@ray-x Yes it is started, it shows diagnostic texts.
@milad-abbasi I can not reproduce with your minimum vimrc. One thing not sure about is I am using Mac+Kitty, may it affect the sequence of initilization.
Can you check adjust your vimrc like this:
lua <<EOF
local nvim_lsp = require('lspconfig')
require'lspconfig'.tsserver.setup{
on_attach = function(client)
require'lsp_signature'.on_attach()
end
}
EOF
@ray-x It now works🤘
I think I just have found a culprit. I had stylelint-lsp
and efm-langserver
also enabled and attached to the buffer. They both were returning
{
signature_help = false,
signature_help_trigger_characters = {},
}
(amongst other capabilities).
After disabling them and leaving only sumneko's lua lsp or tsserver active for buffer I do get signature hints.
@ray-x arte you able to reproduce? Does it help with coming up with the fix?
Yes. this is definitively the cause of the issue. But I do not think it can be fixed. The plugin needs check lsp capacities and only show signature when signature_help is true. Enable the plugin when signature_help is false might cause more trouble if it not supported. Just curious, are you attach to multiple servers in a single buffer? can you do a log dump (in you attach func print(vim.inspect(client.resolved_capabilities)) )
Yes, I am attaching more than one client. Print statement shows:
{
call_hierarchy = false,
code_action = false,
code_lens = false,
code_lens_resolve = false,
completion = false,
declaration = false,
document_formatting = true,
document_highlight = false,
document_range_formatting = false,
document_symbol = false,
execute_command = false,
find_references = false,
goto_definition = true,
hover = false,
implementation = false,
rename = false,
signature_help = false,
signature_help_trigger_characters = {},
text_document_did_change = 1,
text_document_open_close = true,
text_document_save = true,
text_document_save_include_text = false,
text_document_will_save = false,
text_document_will_save_wait_until = false,
type_definition = false,
workspace_folder_properties = {
changeNotifications = true,
supported = true
},
workspace_symbol = false
}
{
call_hierarchy = false,
code_action = {
codeActionKinds = { "", "quickfix", "refactor.rewrite", "refactor.extract" },
resolveProvider = false
},
code_lens = false,
code_lens_resolve = false,
completion = true,
declaration = false,
document_formatting = false,
document_highlight = true,
document_range_formatting = false,
document_symbol = true,
execute_command = true,
find_references = true,
goto_definition = true,
hover = true,
implementation = false,
rename = true,
signature_help = true,
signature_help_trigger_characters = { "(", "," },
text_document_did_change = 2,
text_document_open_close = true,
text_document_save = false,
text_document_save_include_text = false,
text_document_will_save = false,
text_document_will_save_wait_until = false,
type_definition = false,
workspace_folder_properties = {
changeNotifications = false,
supported = false
},
workspace_symbol = true
}
And clients are:
Client: sumneko_lua (id 1)
root: <path>
filetypes: lua
cmd: lua-langserver
Client: efm (id 2)
root: <path>
filetypes: javascript, json, lua, markdown, python, sh, vue, yaml
cmd: efm-langserver
I tried to conditionally attach your plugin by
if client.resolved_capabilities.signature_help then
require "lsp_signature".on_attach()
end
but it didn't work either, which surprised be a bit.
Couldn't your plugin attach to the buffer and use lsp that has the support for required capability?
Hi, @cloggier I updated the code and you can give it a try.
After very quick test it seems like it works now, thanks a lot!
Would you recommend to add require "lsp_signature".on_attach()
within if client.resolved_capabilities.signature_help then
guard or is that not necessary?
Not really. Normally attach the plugin for the lsp client that supports hover/signature_help should be enough. Your case is when the plugin should be triggered, the first available client is efm.
I am closing the issue as the issue was solved, but feel free to comment on the thread for any related questions.
I'm now experiencing the same thing here because of diagnosticsls. If I enable it via lspconfig, the signature help will not appear.
Any suggestions for debugging or solving this ?
I thought the issue was fixed last week.
Can you send the minimum vimrc to reproduce this issue? Also would be great to dump the info by running:
:lua print(vim.inspect(vim.lsp.buf_get_clients(0))) and post the log would be helpful.
Here you go. I've extracted the minimal amount of code from my setup to reproduce this (configured for node project with typescript and eslint). Once I comment out the diagnosticsls section it all works as expected.
call plug#begin()
Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/lsp_signature.nvim'
call plug#end()
lua <<EOF
require'lspconfig'.tsserver.setup{}
require'lspconfig'.diagnosticls.setup{
root_dir = require'lspconfig'.util.root_pattern('package.json'),
filetypes = {
'javascript',
'javascriptreact',
'typescript',
'typescriptreact'
},
init_options = {
linters = {
eslint = {
command = 'node_modules/.bin/eslint',
rootPatterns = { 'package.json' },
debounce = 100,
args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' },
sourceName = 'eslint',
parseJson = {
errorsRoot = '[0].messages',
line = 'line',
column = 'column',
endLine = 'endLine',
endColumn = 'endColumn',
message = '[eslint] ${message} [${ruleId}]',
security = 'severity'
},
securities = {
[1] = 'error',
[2] = 'warning'
},
requiredFiles = {
'.eslintrc',
'package.json'
}
},
},
filetypes = {
javascript = 'eslint',
javascriptreact = 'eslint',
typescript = 'eslint',
typescriptreact = 'eslint',
}
}
}
require'lsp_signature'.on_attach()
EOF
And here's the log you requested: buf_get_clients.txt
I suspect this has something to do with how lsp_signature is displayed and how diagnostics is rendered in the UI. Might be a case of some internal neovim rendering action that just hides the signature help quickly so it looks like it's not working :thinking: I haven't really dug deep into this, so I might be way off on this, hehe.
I am trying to fix your issue. But seems the latest neovim lsp signature for ts/js is broken. So if things still working(after remove diagnositcls), please do not update your neovim and update lsp_signature see if I fixed the issue. An code update was add. I think diagnositcls introduce an empty client and caused some trouble to launch the plugin. I can see from the log after code fix, the plugin was triggered. But as upstream broken, I can not fully verify.
That seems to work @ray-x :+1: . Did your change also make it so the signature text no longer wraps ? I can't remember that being an issue before...but maybe it's just bad memory.
It is great the plugin works for you. I did not change the wrap setup yesterday. And it seems to be wrap correct on my side. In fact, the plugin does not even has a wrap setup in the backend.
Okay mr @ray-x . Then everything is solved! Thank you for fast response and fast fix :)
It works for me in lua but it doesn't work for python with pyright-ls.
This is the output of inspect client:
messages
call_hierarchy = true,
code_action = {
codeActionKinds = { "quickfix", "source.organizeImports" },
workDoneProgress = true
},
code_lens = false,
code_lens_resolve = false,
completion = true,
declaration = false,
document_formatting = false,
document_highlight = {
workDoneProgress = true
},
document_range_formatting = false,
document_symbol = {
workDoneProgress = true
},
execute_command = true,
find_references = {
workDoneProgress = true
},
goto_definition = {
workDoneProgress = true
},
hover = {
workDoneProgress = true
},
implementation = false,
rename = true,
signature_help = true,
signature_help_trigger_characters = { "(", ",", ")" },
text_document_did_change = 2,
text_document_open_close = true,
text_document_save = true,
text_document_save_include_text = false,
text_document_will_save = false,
text_document_will_save_wait_until = false,
type_definition = false,
workspace_folder_properties = {
changeNotifications = false,
supported = false
},
workspace_symbol = {
workDoneProgress = true
}
}
This is my pyright setup
require'lspconfig'.pyright.setup {
cmd = {DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", "--stdio"},
on_attach = function(client, bufnr)
require"lsp_signature".on_attach()
print(vim.inspect(client.resolved_capabilities))
end
}
I had also efm but I disabled it as I saw in the comments above.
The :lua.vim.buf.signature_help() works but the :lua require'lsp_signature'.signature() does not.
Any ideas? Thank you in advance
This issue was caused by pyright cap does not support hover
. However, the signature help can display correctly. So I remove the hover check and hope it will work for you
Yeah, it seems to work now! Thanks for the quick fix!
Sometimes when I type fast in python I get the following
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1022: Failed to switch to window 1065
I guess it has something to do with the changing focus between the hover window of the signature help and the main window.
This issue happen to me as well this week after I update my nvim nightly as well. I think the upstream has an bug when preview closed but not notify neovim.
After very quick test it seems like it works now, thanks a lot!
Hey, I couldn't follow what fixed your issue, I am having a similar setup as yours and I am running efm + sumeko_lua too. Can you please clarify what helped you?
Hi! I am quite keen to get try out this plugin, but as of now it doesn't work. Tried lua file with sumneko's lsp, and python with pyright; didn't get any popups with argument once in
()
after function call for neither of filetypes.Installed with packer like that:
I also have
nvim-compe
if that makes any difference.