You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have recently set up lsp-config, nvim-cmp, mason, mason-lspconfig, luasnip, cmp-nvim-lsp, and a few different LSPs.
My main goal is to be able to autocomplete with snippets with argument placeholders. This works perfectly with clangd. The snippets are selected for standard library functions and even external library methods. Here is a gif example:
Now for Python. My LSP of choice is pylsp and uses jedi_completion. The autocompletion works well for standard functions and even custom functions imported in from a separate file, but not in the case of external libraries.
What happens for these libraries is that the autocompletion does not give a snippet and therefore does not autocomplete with the argument placeholders. However, once already typed out, hitting 'Ctrl+Space' (which calls cmp.mapping.complete()) opens up the autocompletion menu again, this time actually including the snippet for the method. Here is an example with numpy:
So far this seems to occur for numpy, matplotlib, and cv2, but I'm not sure about others.
Is there a way to modify my config so that the autocompletion includes the argument placeholder snippets the first time so that I don't have to perform more keypresses to initiate the snippet?
Here are my work-in-progress configs:
cmp.lua:
return {
-- 'hrsh7th/cmp-buffer',
-- 'hrsh7th/cmp-path',
-- 'hrsh7th/cmp-cmdline',
{
'hrsh7th/cmp-nvim-lsp',
},
{
"L3MON4D3/LuaSnip",
dependencies = {
'saadparwaiz1/cmp_luasnip',
'rafamadriz/friendly-snippets',
},
-- install jsregexp (optional!).
build = "make install_jsregexp",
config = function()
local ls = require("luasnip")
-- local s = ls.snippet
-- local t = ls.text_node
-- local i = ls.insert_node
vim.keymap.set({"i", "s"}, "<C-x>", function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end, {silent = true})
vim.keymap.set({"i", "s"}, "<C-z>", function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end, {silent = true})
-- ls.add_snippets("lua", {
-- s("hello", {
-- t('print("hello world")')
-- })
-- })
end
},
{
'hrsh7th/nvim-cmp',
config = function()
local cmp = require('cmp')
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
experimental = {
ghost_text = true
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
sources = {
{name = 'nvim_lsp'},
{name = 'luasnip'},
-- {name = 'buffer'},
-- {name = 'path'},
},
--- (Optional) Show source name in completion menu
formatting = cmp_format,
mapping = cmp.mapping.preset.insert({
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-q>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false }),
})
})
end
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have recently set up
lsp-config
,nvim-cmp
,mason
,mason-lspconfig
,luasnip
,cmp-nvim-lsp
, and a few different LSPs.My main goal is to be able to autocomplete with snippets with argument placeholders. This works perfectly with
clangd
. The snippets are selected for standard library functions and even external library methods. Here is a gif example:Now for Python. My LSP of choice is
pylsp
and usesjedi_completion
. The autocompletion works well for standard functions and even custom functions imported in from a separate file, but not in the case of external libraries.What happens for these libraries is that the autocompletion does not give a snippet and therefore does not autocomplete with the argument placeholders. However, once already typed out, hitting 'Ctrl+Space' (which calls
cmp.mapping.complete()
) opens up the autocompletion menu again, this time actually including the snippet for the method. Here is an example withnumpy
:So far this seems to occur for
numpy
,matplotlib
, andcv2
, but I'm not sure about others.Is there a way to modify my config so that the autocompletion includes the argument placeholder snippets the first time so that I don't have to perform more keypresses to initiate the snippet?
Here are my work-in-progress configs:
cmp.lua:
lsp.lua:
Beta Was this translation helpful? Give feedback.
All reactions