fix: init.lua
This commit is contained in:
@@ -173,8 +173,8 @@ local function build_prompt(user_input, dirs, conf)
|
|||||||
table.insert(final_sections, table.concat(env_lines, "\n"))
|
table.insert(final_sections, table.concat(env_lines, "\n"))
|
||||||
|
|
||||||
local final_prompt = table.concat(final_sections, "\n\n")
|
local final_prompt = table.concat(final_sections, "\n\n")
|
||||||
-- Replace placeholder "chatgpt.vim" with the actual project name from configuration
|
-- Replace placeholder "%PROJECT_NAME%" with the actual project name from configuration
|
||||||
final_prompt = final_prompt:gsub("%chatgpt.vim%", conf.project_name)
|
final_prompt = final_prompt:gsub("%%PROJECT_NAME%%", conf.project_name)
|
||||||
return final_prompt
|
return final_prompt
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -453,8 +453,13 @@ local function run_chatgpt_current_buffer_command()
|
|||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- GLOBAL FILE COMPLETION FUNCTION
|
-- PUBLIC API
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
M.run_chatgpt_command = run_chatgpt_command
|
||||||
|
M.run_chatgpt_paste_command = run_chatgpt_paste_command
|
||||||
|
M.run_chatgpt_current_buffer_command = run_chatgpt_current_buffer_command
|
||||||
|
|
||||||
|
-- New: Global function for file name auto-completion in ChatGPT prompt
|
||||||
function _G.chatgpt_file_complete(findstart, base)
|
function _G.chatgpt_file_complete(findstart, base)
|
||||||
if findstart == 1 then
|
if findstart == 1 then
|
||||||
local line = vim.fn.getline('.')
|
local line = vim.fn.getline('.')
|
||||||
@@ -469,8 +474,9 @@ function _G.chatgpt_file_complete(findstart, base)
|
|||||||
local conf = config.load()
|
local conf = config.load()
|
||||||
local files = context.get_project_files({'.'}, conf)
|
local files = context.get_project_files({'.'}, conf)
|
||||||
local completions = {}
|
local completions = {}
|
||||||
|
local esc_base = base:gsub("([^%w])", "%%%1")
|
||||||
for _, f in ipairs(files) do
|
for _, f in ipairs(files) do
|
||||||
if f:find(base, 1, true) then
|
if f:match("^" .. esc_base) then
|
||||||
table.insert(completions, f)
|
table.insert(completions, f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user