I'm currently interested in the Language Server Protocol and how to implement it in Vim/Neovim.
hrsh7th / cmp-vsnip Goto Github PK
View Code? Open in Web Editor NEWnvim-cmp source for vim-vsnip
License: MIT License
nvim-cmp source for vim-vsnip
License: MIT License
I'm currently interested in the Language Server Protocol and how to implement it in Vim/Neovim.
Having a weird duplicate expansion. Tab
keys aren't working for jumps.
--Approximate config
-- plugins-snippets.lua
local cmp = require("cmp")
cmp.setup({
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<C-S-j>"] = cmp.mapping(function(fallback)
if vim.fn["vsnip#jumpable"](1) == 1 then
feedkey("<Plug>(vsnip-jump-next")
else
fallback()
end
end, { "s" }),
["<Tab>"] = cmp.mapping(function(fallback)
-- elseif vim.fn["vsnip#available"](1) == 1 then
if vim.fn["vsnip#jumpable"](1) == 1 then
feedkey("<Plug>(vsnip-jump-next", "")
elseif cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
--The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
elseif cmp.visible() then
cmp.select_prev_item()
end
end, { "i", "s" }),
...
end -- setup end
"workspace doc open": {
"prefix": "doc.open.content",
"body": [
"workspace.openTextDocument({",
" content : ${1:\"File content\"},",
" language: \"${2|javascript,typescript,texmate.snippet|}\"",
"});"
],
"description": "Open vs code workspace document"
}
After the commit 18ff44c
the behavior when I press tab changes from expanding the string to the full snippet prefix to now expanding to the first line in the snippet's body.
I am trying to understand the intention behind that change, so that I can modify my workflow or perhaps change my snippet to work with this change.
The way I am using is to first expand to the full "name" of the snippet first and have another mapping to expand it to the full body. Perhaps the change is trying to do both at once but I can't find a way to set my snippet in such a way that it works.
It works well with nvim-compe, vim-vsnip, and vim-vsnip-integ.
Screenshot:
My vsnip snippets:
{
"Date": {
"prefix": ["date"],
"body": ["${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}"],
"description": "Date"
},
"Datetime": {
"prefix": ["datetime"],
"body": ["${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}"],
"description": "Datetime"
}
}
Hi,
Having updated my config today, I've seen that I get no snippets shown in nvim-cmp. I saw that commit 18ff44c seems to have broken my config. However, replacing the line in:
cmp-vsnip/lua/cmp_vsnip/init.lua
Line 18 in 989a8a7
by the same line in the previous commit:
cmp-vsnip/lua/cmp_vsnip/init.lua
Line 14 in 1ae05c6
seems to have solved the issue. Do you have any idea why that should be and if a fallback to the old line is necessary?
Thanks
Some snippets cause the menu to immediately close, when selected with prev/next in the menu. They also insert a messed up version of the snippet.
Here is an example snippet:
{
"msg": {
"prefix": ["msg"],
"body": [
"[$1] $2"
]
}
}
If I now just select the first item (i.e. <c-j>
without confirming!), the menu closes immediately and inserts the first part of the template:
This happens since commit 18ff44c (Improve Symbol handling).
It does not happen for all snippets. I could not find out what exactly makes some snippets cause this problems, while others still work fine.
My nvim-cmp config:
cmp.setup({
snippet = {
expand = function(args)
vim.fn['vsnip#anonymous'](args.body)
end,
},
mapping = {
['<C-j>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i', 'c'}),
['<C-k>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i', 'c'}),
['<CR>'] = function(fallback)
if cmp.visible() and
cmp.get_selected_entry() and
not (cmp.get_selected_entry().source.name == 'nvim_lsp_signature_help') then
cmp.confirm({
select = false,
})
else
fallback()
end
end
},
sources = cmp.config.sources({
{ name = 'vsnip' },
}),
})
When I try to select the snippet hint displayed in the completion menu, I get this error:
E5108: Error executing lua .../.vim/plugged/nvim-cmp/lua/cmp/config/default.lua:24: snippet engine is not configured.
stack traceback:
[C]: in function 'error'
.../.vim/plugged/nvim-cmp/lua/cmp/config/default.lua:24: in function 'expand'
.../.vim/plugged/nvim-cmp/lua/cmp/core.lua:417: in function <.vim/plugged/nvim-cmp/lua/cmp/core.lua:378>
.../.vim/plugged/nvim-cmp/lua/cmp/utils/feedkeys.lua:51: in function <.vim/plugged/nvim-cmp/lua/cmp/utils/feedkeys.lua:49>
Not sure what's missing
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.