@@ -179,15 +179,10 @@ M.setup = function(opts)
179
179
table.sort (M ._chat_agents )
180
180
table.sort (M ._command_agents )
181
181
182
- M .refresh_state ()
183
-
184
- if M .config .default_command_agent then
185
- M .refresh_state ({ command_agent = M .config .default_command_agent })
186
- end
187
-
188
- if M .config .default_chat_agent then
189
- M .refresh_state ({ chat_agent = M .config .default_chat_agent })
190
- end
182
+ M .refresh_state ({
183
+ command_agent = M .config .default_command_agent ,
184
+ chat_agent = M .config .default_chat_agent ,
185
+ })
191
186
192
187
-- register user commands
193
188
for hook , _ in pairs (M .hooks ) do
@@ -238,14 +233,18 @@ M.setup = function(opts)
238
233
Tabnew = ft_completion ,
239
234
}
240
235
236
+ local updates = {
237
+ ChatHelp = function ()
238
+ return { show_chat_help = not M ._state .show_chat_help }
239
+ end ,
240
+ }
241
+
241
242
-- register default commands
242
243
for cmd , _ in pairs (M .cmd ) do
243
244
if M .hooks [cmd ] == nil then
244
245
M .helpers .create_user_command (M .config .cmd_prefix .. cmd , function (params )
245
246
M .logger .debug (" running command: " .. cmd )
246
- if cmd ~= " ChatHelp" then
247
- M .refresh_state ()
248
- end
247
+ M .refresh_state ((updates [cmd ] or function () end )())
249
248
M .cmd [cmd ](params )
250
249
end , completions [cmd ])
251
250
end
@@ -255,15 +254,20 @@ M.setup = function(opts)
255
254
pattern = " *.md" ,
256
255
callback = function (ev )
257
256
M .helpers .schedule (function ()
258
- local path = ev .file
259
257
local buf = ev .buf
260
258
local current_ft = vim .bo [buf ].filetype
261
- if not M .not_chat (buf , path ) and current_ft ~= " markdown.gpchat" then
262
- vim .bo [buf ].filetype = " markdown.gpchat"
263
- elseif M .helpers .ends_with (path , " .gp.md" ) and current_ft ~= " markdown.gpmd" then
264
- vim .bo [buf ].filetype = " markdown.gpmd"
259
+
260
+ if current_ft == " markdown.gpchat" then
261
+ vim .cmd (" doautocmd User GpRefresh" )
262
+ elseif current_ft ~= " markdown.gpmd" then
263
+ local path = ev .file
264
+ if M .helpers .ends_with (path , " .gp.md" ) then
265
+ vim .bo [buf ].filetype = " markdown.gpmd"
266
+ elseif M .not_chat (buf , path ) == nil then
267
+ vim .bo [buf ].filetype = " markdown.gpchat"
268
+ vim .cmd (" doautocmd User GpRefresh" )
269
+ end
265
270
end
266
- vim .cmd (" doautocmd User GpRefresh" )
267
271
end , 1 )
268
272
end ,
269
273
})
@@ -1159,9 +1163,7 @@ M.chat_header = function(buf)
1159
1163
vim .api .nvim_buf_set_lines (buf , 0 , old_header_end + 1 , false , vim .list_slice (lines , 0 , header_end + 1 ))
1160
1164
end
1161
1165
1162
- M .cmd .ChatHelp = function ()
1163
- M .refresh_state ({ show_chat_help = not M ._state .show_chat_help })
1164
- end
1166
+ M .cmd .ChatHelp = function () end
1165
1167
1166
1168
M .cmd .ChatRespond = function (params )
1167
1169
if params .args == " " and vim .v .count == 0 then
0 commit comments