-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with nvim-cmp #5
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi again, thanks for the help! I might have missed something, but I couldn't make it work with your code snippet. In case my request didn't go through: I was asking whether it is possible to add a pair of parenthesis to a cmp completion item which is a function. This was accomplishable by |
Currently that specific feature is not possible. |
Looking forward to this useful feature! |
This feature is indeed very useful, looking forward to it 😄 |
Sorry, currently don't find the resources, but doesn't |
If it does then I can't figure out how to. I just switched from LazyVim to Kickstart and I tried getting the function completion to work like lazy had.and lazy doesn't use the cmp:on_event trick but I have no idea how it gets function completion to work otherwise. |
Okay, it seems like this is a feature of the LSP completion where some servers provide this feature by using snippets. Sorry. |
Yes sir. This is the last reason I still use nvim-autopairs. |
Hello, I'm still looking forward to this useful feature |
Very wholesome, very useful feature. In the meantime try and configure the LSP you use to send snippets for completion. This varies per LSP. That's how I got around it so far. Clangd, jdtls, luals, and pyright all support it. So thats all I need for now. |
If anyone wants this feature before I implement it: local cmp=require('cmp')
local Kind=cmp.lsp.CompletionItemKind
cmp.event:on(
'confirm_done',
function (evt)
if vim.tbl_contains({Kind.Function,Kind.Method},evt.entry:get_completion_item().kind) then
vim.api.nvim_feedkeys('()'..vim.api.nvim_replace_termcodes('<Left>',true,true,true),'n',false)
end
end) |
I was actually thinking about exactly such a solution. Probably just need to make it a liiiittle more advanced, so it does not interfere with server which do actually send additional snippets to add them too. |
@altermo This works great, but I found that it doesn't work on JavaScript/TypeScript arrow functions: const foo = (bar, baz) => bar + baz; I realize that this is trickier, but is this something that would be possible to support? |
How would it work exactly? |
As I was typing out a response to this I realize that it's probably too difficult :) |
I modified @altermo's temporary solution to exclude The local cmp = require('cmp')
local ind = cmp.lsp.CompletionItemKind
local function ls_name_from_event(event)
return event.entry.source.source.client.config.name
end
-- Add parenthesis on completion confirmation
cmp.event:on('confirm_done', function(event)
local ok, ls_name = pcall(ls_name_from_event, event)
if ok and vim.tbl_contains({ 'rust_analyzer', 'lua_ls' }, ls_name) then
return
end
local completion_kind = event.entry:get_completion_item().kind
if vim.tbl_contains({ ind.Function, ind.Method }, completion_kind) then
local left = vim.api.nvim_replace_termcodes('<Left>', true, true, true)
vim.api.nvim_feedkeys('()' .. left, 'n', false)
end
end) |
Hi @mawkler, thanks a lot , I have used your config with pylsp very well |
Is there an official response why something like this isn't implemented in cmp-nvim directly? Or at least a snippet like this for those that don't want to rely on per-autopair plugin implementation. I don't think that any autopair plugin actually needs to insert that parenthesis pair in a special way. Unless it does? P.S. I started searching here after I stumbled upon hrsh7th/nvim-cmp#1672. I also had to include |
It will take some time until I come up with a good design, so in the meantime, I created an experimental version. To use it: require'ultimate-autopair'.init({
require'ultimate-autopair'.extend_default{
--Normal config goes here
},
{profile=require'ultimate-autopair.experimental.cmpair'.init},
}) |
I get error in
My config:
|
I couldn't reproduce the problem, but I think I solved it (9e32091) |
Hi, lovely plugin. Do you support integration with nvim-cmp just like
nvim-autopairs
does?https://github.com/hrsh7th/nvim-cmp/wiki/Advanced-techniques#add-parentheses-after-selecting-function-or-method-item
The text was updated successfully, but these errors were encountered: