nvim-cmp
nvim-cmp copied to clipboard
Parsing error: Error 08:05:18 notify.error ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:411: snippet parsing failed.
FAQ
- [X] I have checked the FAQ and it didn't resolve my problem.
Announcement
- [X] I have checked Breaking change announcement.
Minimal reproducible full config
return {
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-cmdline",
"hrsh7th/cmp-nvim-lsp-document-symbol",
"hrsh7th/cmp-nvim-lsp-signature-help",
},
opts = {
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
local cmp = require("cmp")
local defaults = require("cmp.config.default")()
sources = {
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "path" },
{ name = "nvim_lsp_signature_help" },
},
completion = {
completeopt = "menu,menuone,noinsert",
},
},
config = function(_, opts)
local cmp = require("cmp")
cmp.mapping.preset.insert({
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<c-y>"] = cmp.mapping.complete({ select = false }),
["<c-Y>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
}),
})
cmp.setup(opts)
-- `/` cmdline setup.
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "nvim_lsp_document_symbol" },
}, {
{ name = "buffer" },
}),
})
-- `:` cmdline setup.
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{
name = "cmdline",
option = {
ignore_cmds = { "Man", "!" },
},
},
}),
})
end,
config = function(_, opts)
for _, source in ipairs(opts.sources) do
source.group_index = source.group_index or 1
end
local cmp = require("cmp")
local Kind = cmp.lsp.CompletionItemKind
cmp.setup(opts)
cmp.event:on("confirm_done", function(event)
if not vim.tbl_contains(opts.auto_brackets or {}, vim.bo.filetype) then
return
end
local entry = event.entry
local item = entry:get_completion_item()
if vim.tbl_contains({ Kind.Function, Kind.Method }, item.kind) then
local keys = vim.api.nvim_replace_termcodes("()<left>", false, false, true)
vim.api.nvim_feedkeys(keys, "i", true)
end
end)
end,
},
}
Description
I'm receiving the following parsing error: Error 08:05:18 notify.error ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:411: snippet parsing failed. I've identified that the issue began after the last known working commit for me, "b356f2c". Starting at this commit I begin receiving the error being documented. I went into the code base of nvim-cmp, and printed the input being parsed, and while erroring the input is always $a, followed by the parsing error.
I set debugging within the code base to true, and was able to catch this additional logging on the issue:
08:37:17 msg_show >>> InsertEnter
08:37:17 msg_show ctx: `export async function registerHooks() {`
08:37:17 msg_show unchanged
08:37:17 msg_show >>> CursorMovedI
08:37:21 msg_show >>> CursorMovedI
08:37:21 msg_show >>> TextChangedI
08:37:21 msg_show ctx: ` `
08:37:21 msg_show changed
08:37:21 msg_show path^Irequest^I1^I{
08:37:21 msg_show triggerKind = 1
08:37:21 msg_show }
08:37:21 msg_show nvim_lsp_signature_help^Irequest^I4^I{
08:37:21 msg_show triggerCharacter = " ",
08:37:21 msg_show triggerKind = 2
08:37:21 msg_show }
08:37:23 msg_show >>> CursorMovedI
08:37:23 msg_show >>> TextChangedI
08:37:23 msg_show ctx: ` d`
08:37:23 msg_show changed
08:37:23 msg_show nvim_lsp:tsserver^Irequest^I4^I{
08:37:23 msg_show triggerKind = 1
08:37:23 msg_show }
08:37:23 msg_show buffer^Irequest^I4^I{
08:37:23 msg_show triggerKind = 1
08:37:23 msg_show }
08:37:23 msg_show buffer^Iretrieve^I166
08:37:23 msg_show nvim_lsp:tsserver^Iretrieve^I2051
08:37:23 msg_show parse:407 logging message registerHooks
08:37:23 msg_show parse:407 logging message _c
08:37:23 msg_show parse:407 logging message _f
08:37:23 msg_show parse:407 logging message _h
08:37:23 msg_show parse:407 logging message _l
08:37:23 msg_show parse:407 logging message _p
08:37:23 msg_show parse:407 logging message _s
08:37:23 msg_show parse:407 logging message $a
08:37:23 msg_show Traceback for parsing input
08:37:23 msg_show stack traceback:
08:37:23 msg_show ^I...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:410: in function 'parse'
08:37:23 msg_show ^I...turnrq/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:121: in function 'callback'
08:37:23 msg_show ^I.../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'get_word'
08:37:23 msg_show ^I...turnrq/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:377: in function 'callback'
08:37:23 msg_show ^I.../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'match'
08:37:23 msg_show ^I...urnrq/.local/share/nvim/lazy/nvim-cmp/lua/cmp/source.lua:116: in function 'get_entries'
08:37:23 msg_show ^I...cturnrq/.local/share/nvim/lazy/nvim-cmp/lua/cmp/view.lua:75: in function 'open'
08:37:23 msg_show ^I...cturnrq/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:336: in function <...cturnrq/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:309>
Error 08:37:23 notify.error ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:411: snippet parsing failed.
This issue is not happening in every project, or even every project with this LSP. I'm having issues with a javascript project. More context in the section below related to context.
Steps to reproduce
If you wish to see the issue within the project that it's occurring within you can feel free to clone the repo I'm working within with:
git clone https://github.com/chturner94/Knowledge-Recalled-PF2e-FVTT
or
gh repo clone chturner94/Knowledge-Recalled-PF2e-FVTT
This assumes you are within a project that could cause this issue, more context below if you want to attempt to create a troublesome project.
- Place cursor anywhere within the project.
InsertEnterand begin typing.- With each key stroke, you'll receive an error, as stated above, that parsing has failed. i.e. You want to type const, press
c; error notification, presso; error notification, pressn; error notification, presss; error notification, pressterror notification, pressspace; error notification. It will stop once you complete the symbol name and append it with aspace. You can even back space back into the symbol and completion will begin working. You can type a variable name, followed by=, but after this you'll begin receiving completion errors again.
Expected behavior
When typing you should receive completion context without receiving parsing errors.
Actual behavior
When typing through the project, about 80% of time I'm receiving parsing errors when completion is attempting to occur. I'm not receiving any errors from the LSP. Given this project is the only project I'm having issues with, I thought that maybe there was any issue with the LSP and the data being received by the LSP. It's possible that nvim-cmp can't handle the input being received from the LSP, but what's being output by the LSP in itself doesn't appear to be problematic and most likely it should be something that nvim-cmp should be able to handle.
Additionally, this issue does not occur with commit b356f2c, or any before this commit. I found a commit further back to see if the issue occurred then (a commit from December I believe), and it did not. I then tried every commit from December to present until i encounter the first commit where the problem resumed.
Additional context
I provided the codebase where I'm experiencing this issue, but I'll provide context to the project in the event that someone wishes to try and create a project that the issue occurs within. When using the most current version of nvim-cmp I typically do not have issues with javascript, typescript, or golang. This particular project I admit is more bespoke and is an edge case. It's a module for a tabletop roleplaying platform and I'm using a library for it which allows svelte to transpile to work within the system. It's a javascript project. Here are a few things that I'm doing that I'm not doing in projects that don't have this issues.
- Being a plugin, I have created softlinks inside of a directory called
external/found in the project root which link to the application source code to provide type completion and context to global variables within the application. - Uses Vite as the build system. I have another project using vite without issues.
- Moderately complex ESLINT configuration (other projects with ESLINT have less complex configs)
- Using jsconfig.json file to reference the code found in
external/ - Svelte files are found in my project. I have another svelte project without issues though.
- Complex JSDOC usage.
My suspicion is that JSDOC or typescript typing inside of javascript project might be causing the issue. I've tried suppressing the JSDOC (removing them; and the issue resumes) not sure if there is caching or anything like that though.
Can confirm this bug. Encountered it in a large TypeScript/React Problem and only had the issue in .tsx files. Normal .ts files don't appear to cause this error.
Hm... It seems the snippet is broken. It is truncated?
Note: https://github.com/hrsh7th/nvim-cmp/commit/b356f2c80cb6c5bae2a65d7f9c82dd5c3fdd6038
I think it truncate.
Hm... It seems the snippet is broken. It is truncated?
Note: b356f2c
I think it truncate.
So this is the last commit that is working for me, apologies if I wasn't clear regarding that in the original post, a very truncated version of my actual config (I ommited the commit in the top level minimal config, since it works when I specify this commit:
"hrsh7th/nvim-cmp",
commit = "b356f2c",
dependencies = {
"hrsh7th/cmp-cmdline",
"hrsh7th/cmp-nvim-lsp-document-symbol",
"hrsh7th/cmp-nvim-lsp-signature-help",
},
.
.
.
This is the commit that seems to have broke the plugin for me: b7b2c12
Looking at this commit it appears that utils/snippet.lua is a brand new implementation and file. That is where I'm getting the error as well, specifically at Line 409.
Can confirm this bug. Encountered it in a large TypeScript/React Problem and only had the issue in
.tsxfiles. Normal.tsfiles don't appear to cause this error.
I have the same problem also in normal .ts files
So this is the last commit that is working for me, apologies if I wasn't clear regarding that in the original post, a very truncated version of my actual config (I ommited the commit in the top level minimal config, since it works when I specify this commit:
commit = "b356f2c",
Can confirm this commit is working, thanks for bisecting!
I tried last commit, but this issue isn't solved, last working is b356f2c
After doing some more investigating on this issue, I found a resolution for my project. At this point I'm not sure if it's nvim-cmp issue or an issue with the LSP itself. I'm working on a project where I'm building a plugin for an electron application. In order to get completion I have a folder called external where I'm creating soft links to the project code that is exporting the global variables. Whenever I remove that folder from my project, I can use the most up to date nvim-cmp. I also noted that the reliability (even when using the older version of nvim-cmp) are more reliable and faster when I remove this directory. I"m not sure if this is a size issue, since others mentioned this issu when working on large projects.
I don't want to close the issue unless it can't be resolved and it has something to do with our projects, I don't think this is likely since it did previously work. Seems like there may need to be some sort of exception that the new implementation is able to handle that it currently isn't. I'd be more than happy to gather more information if that would be helpful, but I'm not entirely sure where I should start. I'll leave this open for now, as the maintainer can always close it.
Not sure if anyone else has gathered any more information since their original issues.
I've run into similar issue in a project using Svelte.
While trying to type in insert mode on the *.svelte fules, I get a spam of the following error:
Error executing vim.schedule lua callback: ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:409: snippet parsing failed.
stack traceback:
[C]: in function 'error'
...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:409: in function 'parse'
...xeho91/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:130: in function 'callback'
.../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'get_word'
...xeho91/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:81: in function 'callback'
.../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'get_offset'
...eho91/.local/share/nvim/lazy/nvim-cmp/lua/cmp/source.lua:353: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
It might be related to this issue: https://github.com/hrsh7th/nvim-cmp/issues/1858
Workaround
I pinned nvim-cmp version to commit: https://github.com/hrsh7th/nvim-cmp/commit/b356f2c80cb6c5bae2a65d7f9c82dd5c3fdd6038
Source: https://github.com/hrsh7th/nvim-cmp/issues/1858#issuecomment-2014660238
To anyone using LazyVim, there's the quick snippet that may help you continue to work:
return {
{
-- https://github.com/hrsh7th/nvim-cmp
"hrsh7th/nvim-cmp",
commit = "b356f2c",
pin = true,
},
}
To anyone using LazyVim, there's the quick snippet that may help you continue to work:
return { { -- https://github.com/hrsh7th/nvim-cmp "hrsh7th/nvim-cmp", commit = "b356f2c", pin = true, }, }
Since I'm using LazyVim distro, if I write a simple lua file in my plugins directory does it overwrite all nvim-cmp configuration or does it simply update it?
Tried what @xeho91 said, yet LazyVim is updating to the latests version all the time... Can't find what's wrong in the config 🤔
To anyone using LazyVim, there's the quick snippet that may help you continue to work:
return { { -- https://github.com/hrsh7th/nvim-cmp "hrsh7th/nvim-cmp", commit = "b356f2c", pin = true, }, }Since I'm using LazyVim distro, if I write a simple lua file in my plugins directory does it overwrite all nvim-cmp configuration or does it simply update it?
I can't give an honest answer, because I don't override the default config for nvim-cmp set by LazyVim.
Tried what @xeho91 said, yet LazyVim is updating to the latests version all the time... Can't find what's wrong in the config 🤔
Don't mind me, made it work finally.
@mikededo How exactly did you make it work? I'm having the same issue and have tried pretty much everything.
@Lompad I was having the same issue, and reinstalling everything with the pinned commit version config from the get go solved it for me.
My uneducated guess is that lazy-lock or something on the shared folder were conflicting with the pin commit and preventing it from taking effect.
Same for me. After pinning nvim-cmp to that specific commit as described above, I removed nvim-cmp via the Lazy menu (leader L) and from there I removed the nvim-cmp package (go to the nvim-cmp line and hit 'x'). After that close and re-open nvim and the error is gone.
Thanks for the workaround guys. Now let's hope the real solution will come soon.
I think this has been fixed with one of the latest commits. Just removed the pin to the suggested commit and I did not get this error in the places where I got them last time
So it should be closed?
I don't think so , error is still present on latest cmp sadly
For me the error changed to module 'cmp.utils.snippet' not found: No LuaRocks module found for cmp.utils.snippet, which was resolved after removing the previous pin and updating the module.
I'm still able to reproduce this issue pretty easily but using a different setup. I was messing around with writing a haskell script and I noticed as soon as I typed:
#!/usr/bin/env cabal
{-
- cabal:
-}
Anything written in the cabal spec block below (such as build-depends:) triggered the same error. I modified the error message in parse to be able to see exactly what it's failing to parse and I see the following:
Error executing vim.schedule lua callback: ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:422
: snippet parsing failed: $!
stack traceback:
[C]: in function 'error'
...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:422: in function 'parse'
...s/ryan/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:130: in function 'callback'
.../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'get_word'
...s/ryan/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:81: in function 'callback'
.../.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'get_offset'
.../ryan/.local/share/nvim/lazy/nvim-cmp/lua/cmp/source.lua:353: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
I'm not sure if $! is a valid snippet. I use haskell-tools.nvim to setup my language server and luasnip for my snippet engine, with lsp-zero to take care of some of the setup boilerplate for lspconfig and cmp. My plugin config can be found here
It's also worth noting that reverting to commit b356f2c as stated above solves the issue.
Another interesting thing to note that I just realized: $! is an operator in haskell. Maybe the lsp is providing that to cmp and it's somehow interpreting it as a snippet instead?
it happened when i use react hooks snippets, such as useState。 throw the error info:
Failed to parse snippet. ...10.0/share/nvim/runtime/lua/vim/lsp/_snippet_grammar.lua:177: snippet parsing failed
const [${1:state}, set${1/(.*)/${1:/capitalize}/}] = useState(${2:initValue})$0
diff --git a/lua/cmp/utils/snippet.lua b/lua/cmp/utils/snippet.lua
index 0bd53c8..6bf7359 100644
--- a/lua/cmp/utils/snippet.lua
+++ b/lua/cmp/utils/snippet.lua
@@ -406,7 +406,7 @@ M.NodeType = Node.Type
function M.parse(input)
local result = S.snippet(input, 1)
if not result.parsed then
- error('snippet parsing failed.')
+ return input
end
return result.value
end
I tested it with lemminx and it works fine.
diff --git a/lua/cmp/utils/snippet.lua b/lua/cmp/utils/snippet.lua index 0bd53c8..6bf7359 100644 --- a/lua/cmp/utils/snippet.lua +++ b/lua/cmp/utils/snippet.lua @@ -406,7 +406,7 @@ M.NodeType = Node.Type function M.parse(input) local result = S.snippet(input, 1) if not result.parsed then - error('snippet parsing failed.') + return input end return result.value endI tested it with
lemminxand it works fine.
I was having similar issues. This fixed it for me as well. Thanks!
Bump. Issue persists on latest as of now, in my case for typst files and triggered by writing "1". Workaround of setting commit to "b356f2c" resolves the issue.
when writing any $ in scss files I get following error:
Error executing vim.schedule lua callback: ...local/share/nvim/lazy/nvim-cmp/l
ua/cmp/utils/snippet.lua:409: snippet parsing failed.
stack traceback:
[C]: in function 'error'
...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:409: in function
'parse'
...oweuph/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:185: in function
'_get_word'
...oweuph/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:90: in function '
_set_completion_item'
...oweuph/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:62: in function '
new'
...weuph/.local/share/nvim/lazy/nvim-cmp/lua/cmp/source.lua:367: in function
''
vim/_editor.lua: in function <vim/_editor.lua:0>
Might this be related?
Edit: Fixed it for me, by removing emmet_ls
Same here I'm getting this issue in scss file when I type '$' as @snoweuph mentioned. However, getting rid of emmet_ls did not fix my issue.
Error executing vim.schedule lua callback: ...e/neovim/vanilla/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:409: snippet parsing failed.
stack traceback:
[C]: in function 'error'
...e/neovim/vanilla/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:409: in function 'parse'
...cal/share/neovim/vanilla/lazy/nvim-cmp/lua/cmp/entry.lua:185: in function '_get_word'
...cal/share/neovim/vanilla/lazy/nvim-cmp/lua/cmp/entry.lua:90: in function '_set_completion_item'
...cal/share/neovim/vanilla/lazy/nvim-cmp/lua/cmp/entry.lua:62: in function 'new'
...al/share/neovim/vanilla/lazy/nvim-cmp/lua/cmp/
Try disabling more modules, to see, which other module is also a source of this problem
Try disabling more modules, to see, which other module is also a source of this problem
@snoweuph Thanks I will try that when I get a chance. For now I ended up doing git checkout b356f2c. Cause for some reason this does not work on my lazy config:
"hrsh7th/nvim-cmp",
commit = "b356f2c",
pin = true,
Will do some more troubleshooting later.
@rickalex21 You might have forgotten that the lazy-lock.json also defines a specific version. So either delete nvim-cmp from the list, update the commit number or remove the entire file. depending on your needs.
@rickalex21 You might have forgotten that the
lazy-lock.jsonalso defines a specific version. So either delete nvim-cmp from the list, update the commit number or remove the entire file. depending on your needs.
@freizammer Adding the full commit instead of the 7 digits fixed the issue. Now I'm pinned to the old commit, Thank You.