Closed ckruse closed 9 months ago
Looks like it's failing because it's encountering a non-UTF8 character in the minibuffer next to "main.rs". What does the minibuffer look like when this error would occur?
It's empty.
I will try to replicate and get to the bottom of this. For now you can disable copilot for whatever mode that minibuffer uses? Or are you using global-copilot-mode
?
I am using global-copilot-mode
, but I can switch to an add-hook
for prog-mode-hook
.
Indeed that circumvents the error, nice! Thanks for the workaround!
@ckruse I can't replicate this after installing consult and using consult-buffer
. Would you mind sharing your consult config?
Sorry, I was away from the computer today.
I was able to create a minimal configuration to reproduce this:
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(require 'use-package)
(use-package consult
:ensure t
:bind
("C-x b" . consult-buffer))
(use-package editorconfig
:ensure t)
(use-package s
:ensure t)
(use-package dash
:ensure t)
(add-to-list 'load-path (expand-file-name "copilot.el" user-emacs-directory))
(require 'copilot)
I cloned the copilot.el
repository to ~/.emacs.d/copilot.el
. After starting Emacs enable global-copilot-mode
via M-x and then try to change the buffer: hit C-x b
and then the down arrow. See this video:
https://github.com/zerolfx/copilot.el/assets/175095/8a2219be-f23a-44f1-a51e-94b57d2a60d0
This is the resulting stack trace:
Debugger entered--Lisp error: (wrong-type-argument utf-8-string-p "*scratch*\370\210\200\200\202")
json-serialize((:jsonrpc "2.0" :method "textDocument/didChange" :params (:textDocument (:uri "buffer://%20*Minibuf-1*" :version 1) :contentChanges [(:range (:start (:line 0 :character 0) :end (:line 0 :character 0)) :text "*scratch*�")])) :false-object :json-false :null-object nil)
jsonrpc--json-encode((:jsonrpc "2.0" :method "textDocument/didChange" :params (:textDocument (:uri "buffer://%20*Minibuf-1*" :version 1) :contentChanges [(:range (:start (:line 0 :character 0) :end (:line 0 :character 0)) :text "*scratch*�")])))
#f(compiled-function (arg1 &rest rest) "Send MESSAGE, a JSON object, to CONNECTION." #<bytecode -0x2da648017c624a6>)(#<jsonrpc-process-connection jsonrpc-process-connection-49108166> :method textDocument/didChange :params (:textDocument (:uri "buffer://%20*Minibuf-1*" :version 1) :contentChanges [(:range (:start (:line 0 :character 0) :end (:line 0 :character 0)) :text "*scratch*�")]))
apply(#f(compiled-function (arg1 &rest rest) "Send MESSAGE, a JSON object, to CONNECTION." #<bytecode -0x2da648017c624a6>) #<jsonrpc-process-connection jsonrpc-process-connection-49108166> (:method textDocument/didChange :params (:textDocument (:uri "buffer://%20*Minibuf-1*" :version 1) :contentChanges [(:range (:start (:line 0 :character 0) :end (:line 0 :character 0)) :text "*scratch*�")])))
jsonrpc-connection-send(#<jsonrpc-process-connection jsonrpc-process-connection-49108166> :method textDocument/didChange :params (:textDocument (:uri "buffer://%20*Minibuf-1*" :version 1) :contentChanges [(:range (:start (:line 0 :character 0) :end (:line 0 :character 0)) :text "*scratch*�")]))
jsonrpc-notify(#<jsonrpc-process-connection jsonrpc-process-connection-49108166> textDocument/didChange (:textDocument (:uri "buffer://%20*Minibuf-1*" :version 1) :contentChanges [(:range (:start (:line 0 :character 0) :end (:line 0 :character 0)) :text "*scratch*�")]))
(progn (if (copilot--connection-alivep) nil (copilot--start-agent)) (jsonrpc-notify copilot--connection 'textDocument/didChange (list :textDocument (list :uri (copilot--get-uri) :version copilot--doc-version) :contentChanges content-changes)))
(let* ((range-start (list :line (- (line-number-at-pos beg) copilot--line-bias) :character (- beg (save-excursion (goto-char beg) (line-beginning-position))))) (range-end (if is-insertion range-start (list :line (- (line-number-at-pos end) copilot--line-bias) :character (- end (save-excursion (goto-char end) (line-beginning-position)))))) (text (if is-insertion (buffer-substring-no-properties beg end) "")) (content-changes (vector (list :range (list :start range-start :end range-end) :text text)))) (setq copilot--doc-version (1+ copilot--doc-version)) (progn (if (copilot--connection-alivep) nil (copilot--start-agent)) (jsonrpc-notify copilot--connection 'textDocument/didChange (list :textDocument (list :uri (copilot--get-uri) :version copilot--doc-version) :contentChanges content-changes))))
(save-restriction (widen) (let* ((range-start (list :line (- (line-number-at-pos beg) copilot--line-bias) :character (- beg (save-excursion (goto-char beg) (line-beginning-position))))) (range-end (if is-insertion range-start (list :line (- (line-number-at-pos end) copilot--line-bias) :character (- end (save-excursion ... ...))))) (text (if is-insertion (buffer-substring-no-properties beg end) "")) (content-changes (vector (list :range (list :start range-start :end range-end) :text text)))) (setq copilot--doc-version (1+ copilot--doc-version)) (progn (if (copilot--connection-alivep) nil (copilot--start-agent)) (jsonrpc-notify copilot--connection 'textDocument/didChange (list :textDocument (list :uri (copilot--get-uri) :version copilot--doc-version) :contentChanges content-changes)))))
(progn (save-restriction (widen) (let* ((range-start (list :line (- (line-number-at-pos beg) copilot--line-bias) :character (- beg (save-excursion ... ...)))) (range-end (if is-insertion range-start (list :line (- ... copilot--line-bias) :character (- end ...)))) (text (if is-insertion (buffer-substring-no-properties beg end) "")) (content-changes (vector (list :range (list :start range-start :end range-end) :text text)))) (setq copilot--doc-version (1+ copilot--doc-version)) (progn (if (copilot--connection-alivep) nil (copilot--start-agent)) (jsonrpc-notify copilot--connection 'textDocument/didChange (list :textDocument (list :uri (copilot--get-uri) :version copilot--doc-version) :contentChanges content-changes))))))
(if (or is-insertion is-deletion) (progn (save-restriction (widen) (let* ((range-start (list :line (- ... copilot--line-bias) :character (- beg ...))) (range-end (if is-insertion range-start (list :line ... :character ...))) (text (if is-insertion (buffer-substring-no-properties beg end) "")) (content-changes (vector (list :range ... :text text)))) (setq copilot--doc-version (1+ copilot--doc-version)) (progn (if (copilot--connection-alivep) nil (copilot--start-agent)) (jsonrpc-notify copilot--connection 'textDocument/didChange (list :textDocument (list :uri ... :version copilot--doc-version) :contentChanges content-changes)))))))
(let* ((is-before-change (eq chars-replaced nil)) (is-after-change (not is-before-change)) (is-insertion (and is-after-change (not (equal beg end)))) (is-deletion (and is-before-change (not (equal beg end))))) (if (or is-insertion is-deletion) (progn (save-restriction (widen) (let* ((range-start (list :line ... :character ...)) (range-end (if is-insertion range-start ...)) (text (if is-insertion ... "")) (content-changes (vector ...))) (setq copilot--doc-version (1+ copilot--doc-version)) (progn (if (copilot--connection-alivep) nil (copilot--start-agent)) (jsonrpc-notify copilot--connection 'textDocument/didChange (list :textDocument ... :contentChanges content-changes))))))))
copilot--on-doc-change(12 22 0)
goto-history-element(-1)
next-history-element(1)
next-line-or-history-element(1)
funcall-interactively(next-line-or-history-element 1)
command-execute(next-line-or-history-element)
completing-read-default("Switch to: " #f(compiled-function (str pred action) #<bytecode 0x1d5f7cc0e52260d8>) #f(compiled-function (&rest args2) #<bytecode -0xae280064bcb4a3f>) confirm-after-completion nil consult--buffer-history nil nil)
completing-read("Switch to: " #f(compiled-function (str pred action) #<bytecode 0x1d5f7cc0e52260d8>) #f(compiled-function (&rest args2) #<bytecode -0xae280064bcb4a3f>) confirm-after-completion nil consult--buffer-history nil nil)
#f(compiled-function () #<bytecode 0x10b5c883403177af>)()
consult--with-preview-1((:predicate #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_173> :keys (any)) #f(compiled-function (action arg0) #<bytecode 0x22a987583a87255>) #f(compiled-function (narrow input cand) #<bytecode -0x1849ac57b6ce0e46>) #f(compiled-function (&rest args2) #<bytecode -0xae4d03bbfd08a3f>) #f(compiled-function () #<bytecode 0x10b5c883403177af>))
consult--read-1((#(" *Minibuf-1*�" 0 12 (face consult-buffer multi-category (buffer . " *Minibuf-1*")) 12 13 (invisible t consult-strip t)) #(" *Minibuf-0*�" 0 12 (face consult-buffer multi-category (buffer . " *Minibuf-0*")) 12 13 (invisible t consult-strip t)) #(" *Echo Area 0*�" 0 14 (face consult-buffer multi-category (buffer . " *Echo Area 0*")) 14 15 (invisible t consult-strip t)) #(" *Echo Area 1*�" 0 14 (face consult-buffer multi-category (buffer . " *Echo Area 1*")) 14 15 (invisible t consult-strip t)) #(" *copilot stderr*�" 0 17 (face consult-buffer multi-category (buffer . " *copilot stderr*")) 17 18 (invisible t consult-strip t)) #(" *copilot output*�" 0 17 (face consult-buffer multi-category (buffer . " *copilot output*")) 17 18 (invisible t consult-strip t)) #(" *code-conversion-work*�" 0 23 (face consult-buffer multi-category (buffer . " *code-conversion-work*")) 23 24 (invisible t consult-strip t)) #("*scratch*�" 0 9 (face consult-buffer multi-category (buffer . "*scratch*")) 9 10 (invisible t consult-strip t)) #("*Messages*�" 0 10 (face consult-buffer multi-category (buffer . "*Messages*")) 10 11 (invisible t consult-strip t)) #("*copilot-balancer*�" 0 18 (face consult-buffer multi-category (buffer . "*copilot-balancer*")) 18 19 (invisible t consult-strip t)) #("*GNU Emacs*�" 0 11 (face consult-buffer multi-category (buffer . "*GNU Emacs*")) 11 12 (invisible t consult-strip t))) :require-match confirm-after-completion :prompt "Switch to: " :history consult--buffer-history :sort nil :category multi-category :predicate #f(compiled-function (&rest args2) #<bytecode -0xae280064bcb4a3f>) :annotate #f(compiled-function (&rest args2) #<bytecode -0xae280064bdb0a3f>) :group #f(compiled-function (&rest args2) #<bytecode -0xae280064baaca3f>) :lookup #f(compiled-function (&rest args2) #<bytecode -0xae280064b988a3f>) :preview-key (:predicate #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_173> :keys (any)) :narrow ((32 . "Hidden Buffer") (42 . "Modified Buffer") (98 . "Buffer") (109 . "Bookmark") (112 . "Project")) :state #f(compiled-function (action arg0) #<bytecode 0x22a987583a87255>) :prompt "Select: " :preview-key any :sort t :lookup #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_165>)
consult--read((#(" *Minibuf-1*�" 0 12 (face consult-buffer multi-category (buffer . " *Minibuf-1*")) 12 13 (invisible t consult-strip t)) #(" *Minibuf-0*�" 0 12 (face consult-buffer multi-category (buffer . " *Minibuf-0*")) 12 13 (invisible t consult-strip t)) #(" *Echo Area 0*�" 0 14 (face consult-buffer multi-category (buffer . " *Echo Area 0*")) 14 15 (invisible t consult-strip t)) #(" *Echo Area 1*�" 0 14 (face consult-buffer multi-category (buffer . " *Echo Area 1*")) 14 15 (invisible t consult-strip t)) #(" *copilot stderr*�" 0 17 (face consult-buffer multi-category (buffer . " *copilot stderr*")) 17 18 (invisible t consult-strip t)) #(" *copilot output*�" 0 17 (face consult-buffer multi-category (buffer . " *copilot output*")) 17 18 (invisible t consult-strip t)) #(" *code-conversion-work*�" 0 23 (face consult-buffer multi-category (buffer . " *code-conversion-work*")) 23 24 (invisible t consult-strip t)) #("*scratch*�" 0 9 (face consult-buffer multi-category (buffer . "*scratch*")) 9 10 (invisible t consult-strip t)) #("*Messages*�" 0 10 (face consult-buffer multi-category (buffer . "*Messages*")) 10 11 (invisible t consult-strip t)) #("*copilot-balancer*�" 0 18 (face consult-buffer multi-category (buffer . "*copilot-balancer*")) 18 19 (invisible t consult-strip t)) #("*GNU Emacs*�" 0 11 (face consult-buffer multi-category (buffer . "*GNU Emacs*")) 11 12 (invisible t consult-strip t))) :require-match confirm-after-completion :prompt "Switch to: " :history consult--buffer-history :sort nil :category multi-category :predicate #f(compiled-function (&rest args2) #<bytecode -0xae280064bcb4a3f>) :annotate #f(compiled-function (&rest args2) #<bytecode -0xae280064bdb0a3f>) :group #f(compiled-function (&rest args2) #<bytecode -0xae280064baaca3f>) :lookup #f(compiled-function (&rest args2) #<bytecode -0xae280064b988a3f>) :preview-key (:predicate #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_173> :keys (any)) :narrow ((32 . "Hidden Buffer") (42 . "Modified Buffer") (98 . "Buffer") (109 . "Bookmark") (112 . "Project")) :state #f(compiled-function (action arg0) #<bytecode 0x22a987583a87255>))
consult--multi((consult--source-hidden-buffer consult--source-modified-buffer consult--source-buffer consult--source-recent-file consult--source-file-register consult--source-bookmark consult--source-project-buffer-hidden consult--source-project-recent-file-hidden) :require-match confirm-after-completion :prompt "Switch to: " :history consult--buffer-history :sort nil)
consult-buffer()
funcall-interactively(consult-buffer)
command-execute(consult-buffer)
Look at your stack trace and video clip, your *Minibuf-1*
and *scratch*
buffer names seem to have extra unknown characters. It's a placeholder in the text stack trace and character 200002 in the video (not sure though, it's blurry).
I am not sure show this is possible. Does disabling editorconfig
help? Everything else seems to be just util library functions that don't modify state directly.
Yes, I did notice it.
OK, I digged down further, this character is called a „tofu“ by consult. They add (more or less) random characters to candidates to make them distinguishable. So for example two entries *scratch*
would be two distinct, distinguishable candidates (see e.g. this issue).
I am not sure what to do about this, maybe it would be the best to disable copilot-mode
for minibuffer-mode
?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
I don't think this is a problem for copilot.el. If this is a persistent problem maybe open an issue for a global copilot buffer blacklist config?
Hey there,
after the last commit (82d52b0314b87b682e44fdfacc90116c8bece491), I get this error when using consult-buffer to switch buffers:
I could narrow it down to copilot-mode. When disabling it, the error disappears.
Am I doing something wrong?
Best regards, CK