Skip to content

Commit 0a8a09e

Browse files
committed
WIP: display why I can't change the chat agent
1 parent 2372d53 commit 0a8a09e

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lua/gp/init.lua

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ local M = {
3333
local agent_completion = function()
3434
local buf = vim.api.nvim_get_current_buf()
3535
local file_name = vim.api.nvim_buf_get_name(buf)
36-
if M.not_chat(buf, file_name) == nil then
36+
local is_chat, _ = M.is_chat(buf, file_name)
37+
if is_chat == nil then
3738
return M._chat_agents
3839
end
3940
return M._command_agents
@@ -447,22 +448,22 @@ end
447448

448449
---@param buf number # buffer number
449450
---@param file_name string # file name
450-
---@return string | nil # reason for not being a chat or nil if it is a chat
451-
M.not_chat = function(buf, file_name)
451+
---@return (boolean, string| nil) # is_chat , reason for not being a chat or nil if it is a chat
452+
M.is_chat = function(buf, file_name)
452453
file_name = vim.fn.resolve(file_name)
453454
local chat_dir = vim.fn.resolve(M.config.chat_dir)
454455

455456
if not M.helpers.starts_with(file_name, chat_dir) then
456-
return "resolved file (" .. file_name .. ") not in chat dir (" .. chat_dir .. ")"
457+
return false, "resolved file (" .. file_name .. ") not in chat dir (" .. chat_dir .. ")"
457458
end
458459

459460
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
460461
if #lines < 5 then
461-
return "file too short"
462+
return false, "file too short"
462463
end
463464

464465
if not lines[1]:match("^# ") then
465-
return "missing topic header"
466+
return false, "missing topic header"
466467
end
467468

468469
local header_found = nil
@@ -473,14 +474,15 @@ M.not_chat = function(buf, file_name)
473474
end
474475
end
475476
if not header_found then
476-
return "missing file header"
477+
return false, "missing file header"
477478
end
478479

479-
return nil
480+
return true
480481
end
481482

482483
M.display_chat_agent = function(buf, file_name)
483-
if M.not_chat(buf, file_name) then
484+
local is_chat, _ = M.is_chat(buf, file_name)
485+
if not is_chat then
484486
return
485487
end
486488

@@ -504,7 +506,7 @@ end
504506

505507
M._prepared_bufs = {}
506508
M.prep_chat = function(buf, file_name)
507-
if M.not_chat(buf, file_name) then
509+
if M.is_chat(buf, file_name) then
508510
return
509511
end
510512

@@ -949,8 +951,8 @@ M.chat_respond = function(params)
949951

950952
-- check if file looks like a chat file
951953
local file_name = vim.api.nvim_buf_get_name(buf)
952-
local reason = M.not_chat(buf, file_name)
953-
if reason then
954+
local is_chat, reason = M.is_chat(buf, file_name)
955+
if not is_chat then
954956
M.logger.warning("File " .. vim.inspect(file_name) .. " does not look like a chat file: " .. vim.inspect(reason))
955957
return
956958
end
@@ -1500,7 +1502,9 @@ M.cmd.Agent = function(params)
15001502

15011503
local buf = vim.api.nvim_get_current_buf()
15021504
local file_name = vim.api.nvim_buf_get_name(buf)
1503-
local is_chat = M.not_chat(buf, file_name) == nil
1505+
local is_chat, msg = M.is_chat(buf, file_name)
1506+
print("is_chat ?")
1507+
print(is_chat, msg)
15041508
if is_chat and M.agents[agent_name].chat then
15051509
M.refresh_state({ chat_agent = agent_name })
15061510
M.logger.info("Chat agent: " .. M._state.chat_agent)
@@ -1509,14 +1513,15 @@ M.cmd.Agent = function(params)
15091513
M.logger.info("Command agent: " .. M._state.command_agent)
15101514
else
15111515
M.logger.warning(agent_name .. " is not a valid agent for current buffer")
1516+
M.logger.warning(is_chat)
15121517
M.refresh_state()
15131518
end
15141519
end
15151520

15161521
M.cmd.NextAgent = function()
15171522
local buf = vim.api.nvim_get_current_buf()
15181523
local file_name = vim.api.nvim_buf_get_name(buf)
1519-
local is_chat = M.not_chat(buf, file_name) == nil
1524+
local is_chat, _ = M.is_chat(buf, file_name)
15201525
local current_agent, agent_list
15211526

15221527
if is_chat then

0 commit comments

Comments
 (0)