saadparwaiz1 / cmp_luasnip Goto Github PK
View Code? Open in Web Editor NEWluasnip completion source for nvim-cmp
License: Apache License 2.0
luasnip completion source for nvim-cmp
License: Apache License 2.0
My snippet has more than 1 placeholders for me to type in, example in snipmate-style. How do I create mapping so that I can jump between those placeholders?
Recently a breaking change was introduced (use 0.7 API) will be great to create a tag when the minimum nvim version changes, so we do not have a broken config while the package system catch up.
Thanks!
E5108: Error executing lua ...ite/pack/packer/opt/cmp_luasnip/lua/cmp_luasnip/init.lua:132: attempt to index local 'sn
ip' (a nil value)
stack traceback:
...ite/pack/packer/opt/cmp_luasnip/lua/cmp_luasnip/init.lua:132: in function 'execute'
...re/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/source.lua:360: in function 'execute'
...are/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/entry.lua:439: in function 'execute'
...hare/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/core.lua:468: in function <43/168e(25%)/[Loadingkworkspace]
t/nvim-cmp/lua/cmp/core.lua:467> 42/275 (14%) [Loading workspace]
...site/pack/packer/opt/nvim-cmp/lua/cmp/utils/feedkeys.lua:51: in function <...site/pack/packer/┌psumneko_lua
lua/cmp/utils/feedkeys.lua:49>
Snippets triggers no longer work? Is this due to new changes to luasnip ?
Would you like a min config for this ?
I would like to revive this issue and ask if you could add native choice node integration into this cmp source. While it certainly possible to create an alternative popup menu, having choice nodes integrated will streamline workflows (unified settings and styles). Thanks for considering.
Neovim freezes when pressing tab or strg-I
Pressing tab or strg-I in normal mode without there being a double-dot ':' put in.
I tracked the problem down to this function.
cmp_luasnip/lua/cmp_luasnip/init.lua
Line 117 in 1809552
hrsh7th/nvim-cmp#157 (comment) (TLDR when LSP source is active some snippets from LuaSnip source aren't visible in popupmenu)
I thought this was a nvim-cmp
issue, but @hrsh7th said that this issue is related to LuaSnip source
Hey I'm using Packer and I can't seem to install this plguin I get this error:
✗ Failed to install saadparwaizl/cmp_luasnip
Errors:
Cloning into '/home/dan/.local/share/nvim/site/pack/packer/start/cmp_luasnip'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Not really sure whats going on here I have my github ssh key set up correctly as about 20 other plugins have no problem installing.
I have been following this tutorial https://www.youtube.com/watch?v=ub0REXjhpmk but fail in installing this plugin.
my lua
folder:
.
├── abbreviations.lua
├── gitsigns-settings.lua
├── keybindings.lua
├── lualine-settings.lua
├── nvim-autopairs-settings.lua
├── nvim-cmp-settings.lua
├── nvim-comment-settings.lua
├── nvim-lspinstall-settings.lua
├── nvim-sets.lua
├── nvim-tree-settings.lua
├── plugins.lua
├── solarized-theme-settings.lua
init.lua:
-- packer and plugins
require('plugins')
-- built-in settings
require('keybindings')
require('nvim-sets')
require("abbreviations")
-- plugins settings
-- cmp needs to be first
require("nvim-cmp-settings")
require('lualine-settings')
require('solarized-theme-settings')
require("nvim-tree-settings")
require("nvim-lspinstall-settings")
require("gitsigns-settings")
require("nvim-comment-settings")
require("nvim-autopairs-settings")
plugins.lua (where packer is ):
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd 'packadd packer.nvim'
end
return require('packer').startup(function()
-- Packer can manage itself
-- package manager made in lua
use 'wbthomason/packer.nvim'
use {
'hrsh7th/nvim-cmp'
}
-- many other plugins
-- a collection of very much quantity of snippets for many langs
use {
'rafamadriz/friendly-snippets'
}
-- snippets engine
use {
'L3MON4D3/LuaSnip'
}
-- have that snippets inside cmp
use {
'saadparwaiz1/cmp_luasnip'
}
end)
and nvim-cmp
settings:
-- all nvim-cmp sub plugins configured in one setup
-- https://github.com/hrsh7th/cmp-nvim-lua
-- https://github.com/hrsh7th/cmp-buffer
-- https://github.com/saadparwaiz1/cmp_luasnip
require'cmp'.setup {
snippet = {
expand = function(args)
require"luasnip".lsp_expand(args.body)
end
},
sources = {
{ name = 'nvim_lua' },
{ name = 'path' },
{ name = 'buffer' },
{ name = 'luasnip' }
}
}
i tried to use your config from readme, but as you can see i cant config nvim-cmp
inside packer because i have its configuration in nvim-cmp-settings.lua
, but i tried to respect that order.
when i enter python file, for example
i dont get any snippets
for the for
keyword.
any ideas?
I am getting this error when I try to install cmp_luasnip
Using packer:
use({ "L3MON4D3/LuaSnip" })
-- auto-completion engine
use({
"hrsh7th/nvim-cmp",
config = [[require('config.nvim-cmp')]],
after = "lspkind-nvim",
requires = {
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lua",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-omni",
},
})
use({ "saadparwaiz1/cmp_luasnip" })
use({
"hrsh7th/cmp-nvim-lua",
after = "cmp_luasnip",
})
-- nvim-cmp completion sources
use({ "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" })
use({ "hrsh7th/cmp-path", after = "nvim-cmp" })
use({ "hrsh7th/cmp-buffer", after = "nvim-cmp" })
use({ "hrsh7th/cmp-omni", after = "nvim-cmp" })
Here is my nvim-config
Luasnip's commit @737a2e7 introduced the possibility to specify a "luasnip" field in a snippet JSON file so the snippets can autotrigger.
If that field is set and autotrigger is true, the snippet will not be listed in the nvim-cmp menu. I believe it should show up in the cmp menu, no matter the autotrigger behavior.
Example snippet config
"uuid": {
"prefix": "UUID",
"body": [
"${CURRENT_YEAR}${CURRENT_MONTH}${CURRENT_DATE}${CURRENT_HOUR}${CURRENT_MINUTE}"
],
"description": "UUID",
"luasnip": {
"autotrigger": true
}
},
[nvim-cmp] sources[number].opts is deprecated.
[nvim-cmp] Please use sources[number].option instead.
to:
sources = {
{ name = 'luasnip', options = { use_show_condition = false } },
-- more sources
},
(Disclaimer) I already adressed this problem in #53 issue and i'm sry for the duplicate.
Neovim is freezing when pressing tab in normal mode. To be exact this issue seems to be only with neovim-qt, but i don't know why.
I originally thought the problem came from the resolve method in the init file, but i actually found out it is caused by multiple functions like this:
cmp_luasnip/lua/cmp_luasnip/init.lua
Line 106 in 1809552
cmp_luasnip/lua/cmp_luasnip/init.lua
Line 120 in 1809552
Hi!
There were some additions to luasnip, some time ago actually, where lua-pattern-triggers may now be defined via trigEngine
. I think it would make sense to handle snippets where it is set to "pattern" like those where regTrig is set, the other predefined ones could (with lots of effort) be handled similarly, but I don't think that's really worth it.
For this to work, luasnip needs some so cmp_luasnip can tell whether a snippet has a lua-pattern as its trigger (because trigEngine is just some function, and I don't think it should be exposed)
I can implement this, but pretty busy right now, so will take some time.
Consider the following LuaSnip config:
local ls = require 'luasnip'
ls.config.set_config {
history = true,
updateevents = 'TextChanged,TextChangedI',
}
local extras = require 'luasnip.extras'
local fmt = require('luasnip.extras.fmt').fmt
local i = ls.insert_node
local rep = extras.rep
local s = ls.s
ls.snippets = {
lua = {
s('lr', fmt("local {} = require '{}'", { i(1), i(2) })),
s('<', fmt('<{}>{}</{}>', { i(1), i(2), rep(1) })),
s('</', fmt('<{}/>', { i(1, '') })),
},
}
Replicate:
lr~ Snippet
in the completion dropdown.<~ Snippet
and </~ Snippet
</~ Snippet
option alone.Can you replicate this config, and if so, is this the desirable outcome? It seems like it is dismissing the </
options, perhaps because of the forward slash?
I created some postfix snippets.
I noticed that they always correctly expand, but they are either not shown in the completion list or are only shown if they fully written out. I have not yet been able to figure out when one or the other happens.
I don't have this problem with non-postfix snippets.
My config https://github.com/pogopaule/dotfiles/blob/master/nvim/lua/pogopaule/plugins/luasnip.lua
Hi! If I have the following snippets
local ls = require('luasnip')
local i = ls.insert_node
local fmta = require('luasnip.extras.fmt').fmta
local line_begin = require('luasnip.extras.expand_conditions').line_begin
return {
-- Lua
s(
{ trig = 'rq', dscr = 'Require' },
fmta(
[[
require('<>')
]],
{
i(1, 'package'),
}
),
{ condition = line_begin }
),
}
then cmp shows the rq
completion even when I'm not at the beginning of line. Is it possible to filter such snippet from the completion menu?
I met a confused problem after enabling this plugin, the treesitter highlight would be ineffective in the first buffer. But highlight will be restored in next buffers, whatever methods to open them.
Environment:
NVIM v0.7.0-dev+1233-gabbc9148d
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by p8zhang@l1sw-env
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/host/workdir/local/share/nvim"
Run :checkhealth for more info
Steps to Reproduce:
download the file as miniconf.lua
,
miniconf.txt
install the packer.nvim
, ignore this step if it has been installed,
run nvim -u miniconf.lua +PackerSync
wait for the completion of process of packer.nvim, then open a lua code, python code or c/cpp code file use :e <somefile>
,
you will found no highlight enabled but highlight group created by treesitter could be found in output of command :hi
,
open another buffer, you could found the highlight enabled.
Okay, so it's gonna look really bad on my profile that all I've been doing on github is complain to people about licenses (I use sr.ht instead of github for code hosting, so I don't have any projects here) but... could you please put a license on this plugin? Thanks!
I noticed this autocommand in plugin/cmp_luasnip.lua
:
autocmd User LuasnipSnippetsAdded lua require'cmp_luasnip'.refresh()
So I assumed that this causes snippets to be automatically reloaded once I add a new snippet. However, that doesn't seem to be the case.
The help docs for luasnip show this:
After snippets were lazy-loaded, the
User LuasnipSnippetsAdded
-event will be triggered.
There is no mention of this event being called when the snippet definitions change.
So I don't think this autocommand works as intended.
I am not even sure how to achieve this since Lua caches all modules so maybe luasnip
would need to be reloaded somehow.
Hey I've got a bunch of snips in LuaSnipListAvailable
like this one:
{
description = { "Alert - Info background" },
name = "rh-color-blue-50",
regTrig = false,
trigger = "--rh-color-blue-50",
wordTrig = true
}
loaded via
require 'luasnip.loaders.from_vscode'.lazy_load { paths = {
'~/Developer/redhat-ux/red-hat-design-tokens/editor/vscode'
} }
sources config is
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
}, {
{ name = 'luasnip', option = { use_show_condition = false } },
}, {
{ name = 'treesitter' },
{ name = 'buffer', keyword_length = 3 },
}, {
{ name = 'plugins' },
{ name = 'nvim_lua' },
{ name = 'npm', keyword_length = 4 },
{ name = 'fish' },
{ name = 'calc' },
{ name = 'emoji' },
}),
but none of them are showing up when i type --rh-color
. Y?
config: https://github.com/bennypowers/dotfiles/blob/master/.config/nvim/lua/config/cmp.lua
vscode extension bundle: https://github.com/RedHat-UX/red-hat-design-tokens/releases/tag/v1.0.0-beta.9
Hi!
Luasnip is removing direct access to ls.snippets
(and changing the internal snippet-storage), which means that we'll have to adapt cmp_luasnip
to no longer store an index into the ft-tables.
It will still be possible to get a list of snippets by filetype, and indices into these would work, but storing a direct reference, in some way, to the snippet would be preferable (imo).
I opened an issue in cmp
about just that, not sure if it'll lead to changes in cmp, if it doesn't, we'll implement some snippet->key
/key->snippet
-conversion in luasnip.
I'm not sure if it'll be easy to adapt the cache, haven't really thought about it yet, this is more of a FYI :P
Hello I just re-post here the issue: L3MON4D3/LuaSnip#179
When I open or close parenthesis in python I get the following 3 snippets no matter the function:
Can I disable them somehow? I don't think I had the same problem a couple of days ago.
Thank you in advance.
Every now and then I get the error below. I've tried to find a way to reproduce it but it's very difficult. I think it only occurs after I run source <afile> | PackerCompile
after saving my init.lua
, and it appears to trigger randomly every now and then when I type in insert mode and a snippet appears as the hovered selection in the popup menu.
Without a way to reproduce it's not much help but I still wanted to post this issue to hear if there's an easy fix or if anyone else is having the same issue.
Error executing vim.schedule lua callback: ...e/pack/packer/start/cmp_luasnip/lua/cmp_luasnip/init.lua:106: attempt to index a nil value
stack traceback:
...e/pack/packer/start/cmp_luasnip/lua/cmp_luasnip/init.lua:106: in function 'resolve'
.../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:348: in function 'resolve'
...e/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/entry.lua:454: in function 'resolve'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/view.lua:225: in function 'fn'
.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:41: in function <.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:39>
I was thinking that a potential fix for the snippets with regexes as trigger (that most of the time misbehave) and I came up with an idea that can potentially fix it.
If the regex is capable of matching the current input, then the current input should be the item in the list.
If it does not then the input in the list could be a string derived from the pattern (I mean derive in the academic sense).
For instance:
A snippet with the regex
lorem(%d*)
For a text lorem
should return lorem
as item for the list (because the pattern matches the text).
For a text lor
should return lorem0
as item for the list (because lorem0
is a minimal string derived from the pattern).
The derivations from regexes to strings can be hard to implement, but fortunately in this case lua patterns are very simple so they should be easily derivable.
Extracted from L3MON4D3/LuaSnip#1006
This comes from a slight annoyance of duplicated information for no reason.
With a simple snippet without explicit description, the doc looks like:
You can see we have modeline
repeated twice in the doc popup
(and even 4 times if we count the completion popup and what I wrote / the inserted completion)
I would like to at least remove the docstring when it is the same as the trigger/name of the snippet.
Here is a simulation of the result I'd like to have:
👉 I'd even argue that when the snippet name is the same as the trigger (which is the default when the name isn't specified when defining a snippet), we could remove the name, or replace it with something else 👀
@L3MON4D3 mentioned we could just compare the name/trigger with the docstring and not display it if it's the same
Hi @saadparwaiz1, thank you for creating this plugin.
Please committing the lua-formatter config file. Because you properly don't want other people to change your tab-size 😄
Is it difficult to give a choice as a completion candidate when you are in a choice node?
Just FYI, Luasnip now supports docstrings (textual representations) of snippets via snip:get_docstring()
, could be interesting to display in the documentation, if you'd like to support that :)
He removed global variables such as Luasnip_current_nodes
.
I like this plugin, but all other cmp
result items automatically load when cycling through the list with <C-n>
.
How can I make luasnip snippets do that as well so i dont have ot actually fully confirm them
Error detected while processing TextChangedI Autocommands for "*":
E5108: Error executing lua ...user/.vim/plugged/cmp_luasnip/lua/cmp_luasnip/init.lua:47: attempt to index a boolean value
Press ENTER or type command to continue
Any idea what's causing this? I am trying to make cmp work with luasnip. I have no config for luasnip nor for cmp_luasnip. My config for cmp is the following:
local has_words_before = function()
local cursor = vim.api.nvim_win_get_cursor(0)
return not vim.api.nvim_get_current_line():sub(1, cursor[2]):match('^%s$')
end
local luasnip = require('luasnip')
local cmp = require('cmp')
cmp.setup {
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = {
['<Tab>'] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n', true)
elseif has_words_before() and luasnip.expand_or_jumpable() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function()
if vim.fn.pumvisible() == 1 then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n', true)
elseif luasnip.jumpable(-1) then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '', true)
end
end, { 'i', 's' }),
},
sources = {
{ name = "luasnip" },
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "path" },
},
}
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.