Skip to content

Incorrectly treating %20 in filename as a capture index #1524

@Tlunch

Description

@Tlunch

The error I am seeing:

[CopilotChat] [ERROR] invalid capture index
[CopilotChat] stack traceback:
[CopilotChat]   ...hare/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/init.lua:162: in function <...hare/nvim/lazy/CopilotChat.nvim/lu
a/CopilotChat/init.lua:159>
[CopilotChat]   [C]: in function 'gsub'
[CopilotChat]   ...e/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/prompts.lua:340: in function 'resolve_prompt'
[CopilotChat]   ...hare/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/init.lua:426: in function <...hare/nvim/lazy/CopilotChat.nvim/lu
a/CopilotChat/init.lua:425>
[CopilotChat]   [C]: in function 'xpcall'
[CopilotChat]   ...hare/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/init.lua:166: in function <...hare/nvim/lazy/CopilotChat.nvim/lu
a/CopilotChat/init.lua:158>

The directory name has a %20 in it, and i believe lua is trying to substitute a capture in because of that.

I think this is being caused by what is now this line: prompts.lua

config.system_prompt = config.system_prompt:gsub('{DIR}', source.cwd())

I think treating the result as a raw result of a function would protect against this:

config.system_prompt = config.system_prompt:gsub('{DIR}', function() return source.cwd() end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions