David-Kunz / gen.nvim

Neovim plugin to generate text using LLMs with customizable prompts
The Unlicense
992 stars 64 forks source link

problem with rust #23

Closed joske closed 8 months ago

joske commented 8 months ago

Hi,

I tried this plugin on go code, and it worked there, but when I try on some rust code, I get this:

Error executing vim.schedule lua callback: /Users/jos/.local/share/nvim/lazy/gen.nvim/lua/gen/init.lua:99: invalid capture index
stack traceback:
[C]: in function 'gsub'
/Users/jos/.local/share/nvim/lazy/gen.nvim/lua/gen/init.lua:99: in function 'substitute_placeholders'
/Users/jos/.local/share/nvim/lazy/gen.nvim/lua/gen/init.lua:113: in function 'exec'
/Users/jos/.local/share/nvim/lazy/gen.nvim/lua/gen/init.lua:200: in function 'cb'
/Users/jos/.local/share/nvim/lazy/gen.nvim/lua/gen/init.lua:178: in function 'on_choice'
...are/nvim/lazy/dressing.nvim/lua/dressing/select/init.lua:78: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

On other rust snippets it did work.

wishuuu commented 8 months ago

Hi @joske

It looks like issue similar to Stack thread: https://stackoverflow.com/questions/7787509/lua-gsub-special-replacement-producing-invalid-capture-index

Are you able to provide problematic snippet for futher inspection?

Best regards Oskar

joske commented 8 months ago

Yes, on this file it failed consistently: https://github.com/joske/ripperx4/blob/master/src/musicbrainz.rs

David-Kunz commented 8 months ago

Thanks for reporting, I can reproduce this with the following text:

%20

I'm not sure how to properly escape this.

Error executing vim.schedule lua callback: gen.nvim/lua/gen/init.lua:99: invalid capture index
wishuuu commented 8 months ago

Hi @David-Kunz

I'm unable to check it right now, but I found that calling content = string.gsub(content, "%%", "%%%%") before substituting "%$text" should do the trick. % is escape character for Lua gsub, so i every single '%' should be replaced with double '%%' to prevent it from trying generating any special tokens.

Cheers, Oskar

David-Kunz commented 8 months ago

Thank you, @wishuuu , that works!

The issue is solved with #27 .