nomnivore / ollama.nvim

A plugin for managing and integrating your ollama workflows in neovim.
MIT License
308 stars 22 forks source link

Error on $sel prompts when text contains % #25

Open amfl opened 4 months ago

amfl commented 4 months ago

Prompts that use $sel fail when the selected text contains the string %2.

Neovim throws an error, and no prompt is submitted.

> Error executing vim.schedule lua callback: ...l/.local/share/nvim/lazy/ollama.nvim/lua/ollama/init.lua:183: invalid capture index                           
stack traceback:
        [C]: in function 'gsub'
        ...l/.local/share/nvim/lazy/ollama.nvim/lua/ollama/init.lua:183: in function 'parse_prompt'
        ...l/.local/share/nvim/lazy/ollama.nvim/lua/ollama/init.lua:249: in function 'callback'
        ...l/.local/share/nvim/lazy/ollama.nvim/lua/ollama/init.lua:205: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

This is because gsub treats the % character a bit magically!

https://www.lua.org/pil/20.4.html suggests escaping any % characters first, but there might be other solutions too.

s2 = string.gsub(s2, "%%", "%%%%")
snoweuph commented 3 weeks ago

I had a similar bug, and did a pr to fix it. Seems to be fixed with my #32