Skip to content

Commit 800d8f6

Browse files
committed
feat: looser chat file condition (issue: #106)
- file and topic headers not mandatory - current conditions: .md, chat dir, header section break
1 parent 553d49b commit 800d8f6

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lua/gp/init.lua

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,22 @@ M.not_chat = function(buf, file_name)
451451
return "resolved file (" .. file_name .. ") not in chat dir (" .. chat_dir .. ")"
452452
end
453453

454-
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
455-
if #lines < 5 then
456-
return "file too short"
454+
local extension = vim.fn.fnamemodify(file_name, ":e")
455+
if extension ~= "md" then
456+
return "file extension is not .md"
457457
end
458458

459-
if not lines[1]:match("^# ") then
460-
return "missing topic header"
461-
end
459+
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
462460

463-
local header_found = nil
464-
for i = 1, 10 do
465-
if i < #lines and lines[i]:match("^- file: ") then
466-
header_found = true
461+
local header_break_found = false
462+
for i = 2, 20 do
463+
if i < #lines and lines[i]:match("^%-%-%-%s*$") then
464+
header_break_found = true
467465
break
468466
end
469467
end
470-
if not header_found then
471-
return "missing file header"
468+
if not header_break_found then
469+
return "missing header break"
472470
end
473471

474472
return nil

0 commit comments

Comments
 (0)