neoclide / coc-snippets

Snippets solution for coc.nvim
970 stars 41 forks source link

UltiSnips string interpolation does not work. #323

Open nonetallt opened 1 year ago

nonetallt commented 1 year ago

Platform information:

Relevant plugins used:

I'm trying to use string interpolation for dynamic snippet content, as described in section 4.4 of the UltiSnips documentation. Given that there's a checkmark next to Execute vim, python and shell code in snippet in the readme of this repository while another bulletpoint makes a reference to Execute shell code with custom shabang (will not support), it is implied that string interpolation should indeed be supported by this extension.

However, as far as I can tell, none of the various interpolation modes work. I've tested this with shell, python and vimscript and I'm getting a variation of this error for each of them:

[coc.nvim]: UnhandledRejection: Vim:E121: Undefined variable: v 
Error: request error on "nvim_eval" - Vim:E121: Undefined variable: v 
    at pX (/home/nonetallt/.config/nvim/plugged/coc.nvim/build/index.js:194:10656)
    at Do.resolve (/home/nonetallt/.config/nvim/plugged/coc.nvim/build/index.js:203:2810)
    at /home/nonetallt/.config/nvim/plugged/coc.nvim/build/index.js:206:1476        
    at Array.map (<anonymous>)                                                                          
    at Ac.evalCodeBlocks (/home/nonetallt/.config/nvim/plugged/coc.nvim/build/index.js:206:1445)     
    at gm.resolve (/home/nonetallt/.config/nvim/plugged/coc.nvim/build/index.js:249:728)    
    at runMicrotasks (<anonymous>)   
    at processTicksAndRejections (node:internal/process/task_queues:96:5) 

The only change between interpolation modes is that the "Undefined variable" is whatever word follows after the backticks or exclamation mark. Here's an example snippet that causes the error above:

snippet test-vim "This is a test vim snippet"
`!v system('echo test')`
endsnippet

Another variation, this one for shell interpolation:

snippet test-shell "This is a test shell snippet"
`echo foo`
endsnippet

The shell variation results in Undefined variable: echo. I've tried these snippets with the basic UltiSnips expand command and they work correctly, just not when invoked through this plugin. I don't see this issue as being addressed very clearly despite looking through the previous issues in this repostory. I did manage to find the coc-ultisnips plugin, which might suit my purposes better. However it's still unclear to me whether this plugin is supposed to support string interpolation in snippets or not? If not, then it should addressed clearly in the readme.

Edit: There seems to be something weird going on with the loading of the snippets. Sometimes after I've had neovim open for a longer period (and probably tinkered with the snippets file by editing and saving it), a second entry gets added to the snippet autocompletion menu. See the following picture for reference:

bug

Here I'm working with a "namespace" snippet that uses string interpolation with vimscript. Notice how two different snippets are sourced:

The one without quotes works but the one with quotes errors with the expected undefined variable. For some reason, only the snippet with quotes is added whenever I open the editor.

chemzqm commented 1 year ago

Can't reproduce, the snippets with string interpolation work as expected for me.