hrsh7th / vim-vsnip

Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
MIT License
876 stars 37 forks source link

'$' character in snippet body causes error in 'vsnip#to_string' #245

Closed Kamholtz closed 2 years ago

Kamholtz commented 2 years ago

The presence of '$' in snippets seems to result in an error and does not expand:

Error executing vim.schedule lua callback: {"result": [false, null, 0], "text": "$('

')"} stack traceback: [C]: in function 'vsnip#to_string' ...\site\pack\packer\start\cmp-vsnip/lua/cmp_vsnip/init.lua:40: in function 'resolve' ...-data\site\pack\packer\start\nvim-cmp/lua/cmp/source.lua:348: in function 'resolve' ...m-data\site\pack\packer\start\nvim-cmp/lua/cmp/entry.lua:452: in function 'resolve' ...im-data\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>

The snippet causing this error:

{
    "JQuery div": {
        "prefix": "jdiv",
        "body": [
            "$('<div />')"
        ]
    }
}

Removing the '$' in the body array allows the snippet to expand without error. The snippet as is works in VSCode, so not sure if this is considered a bug or just a difference between VSCode snippets and this plugin. I suspect it is trying to expand the '$' and following characters as if it were a placeholder. Is there a way to escape the '$' in the meantime?

hrsh7th commented 2 years ago

You should escape $ with \\