Skip to content

Commit 8098412

Browse files
author
Kang Tu
committed
Add progress message during gptel sync wait loop
1 parent c06ddf9 commit 8098412

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎ai-code-prompt-mode.el‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,19 @@ Only works when gptel package is installed, otherwise shows error message."
331331
(while (not done)
332332
(when quit-flag
333333
(keyboard-quit))
334+
;; Show progress without flooding the *Messages* log.
335+
(let ((message-log-max nil))
336+
(message "Waiting for GPTel response... %ds (C-g to cancel)"
337+
(floor (- (float-time) start-time))))
334338
(when (> (- (float-time) start-time) ai-code-gptel-sync-timeout)
335339
;; Try to abort any running processes
336340
(gptel-abort temp-buffer)
337341
(setq done t
338342
error-info (format "Request timed out after %d seconds" ai-code-gptel-sync-timeout)))
339343
;; Use sit-for to process events and allow interruption
340344
(sit-for 0.1)))
341-
;; Clean up temp buffer
345+
;; Clear the progress message and clean up temp buffer
346+
(message nil)
342347
(when (buffer-live-p temp-buffer)
343348
(kill-buffer temp-buffer)))
344349
(cond

‎test/test_ai-code-prompt-mode.el‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,35 @@ tools on the user's machine, so tool use is suppressed for the request."
235235
"Truncated"
236236
(ai-code-test--gptel-sync-error-message "Truncate this prompt")))))
237237

238+
(ert-deftest ai-code-test-call-gptel-sync-shows-waiting-message ()
239+
"The blocking wait should show progress and clear it afterwards.
240+
The progress message must stay out of the *Messages* log."
241+
(let ((callback nil)
242+
(messages nil)
243+
(logged-waiting nil))
244+
(ai-code-test-with-stub-gptel
245+
(lambda (_question &rest args)
246+
(setq callback (plist-get args :callback)))
247+
(cl-letf (((symbol-function 'sit-for)
248+
(lambda (&rest _args)
249+
(funcall callback "ANSWER"
250+
'(:status "HTTP/2 200" :error nil))))
251+
((symbol-function 'message)
252+
(lambda (format-string &rest args)
253+
(let ((text (and format-string
254+
(apply #'format format-string args))))
255+
(when (and text message-log-max
256+
(string-match-p "GPTel" text))
257+
(setq logged-waiting t))
258+
(push text messages)))))
259+
(should (equal "ANSWER" (ai-code-call-gptel-sync "Question")))))
260+
(should (cl-some (lambda (text)
261+
(and text (string-match-p "Waiting for GPTel" text)))
262+
messages))
263+
(should-not logged-waiting)
264+
;; The most recent message call clears the echo area.
265+
(should (null (car messages)))))
266+
238267
(ert-deftest ai-code-test-custom-prompt-suffix-provider-respects-switch ()
239268
"The custom suffix provider should honor the legacy suffix switch."
240269
(let ((ai-code-prompt-suffix-functions

0 commit comments

Comments
 (0)