Subject: bug#70927: 30.0.50; track-changes assertion when shutting down eglot

From: Michael Albinus <[email-masked]>
Date: Tue, 14 May 2024 11:14:42 +0200

Eli Zaretskii <[email-masked]> writes:

Hi,

>> When `eglot-autoshutdown` is set, killing eglot buffers fails with a
>> track-changes assertion because, from what I can tell,
>> `eglot--signal-textDocument/didChange` is called when
>> `eglot--track-changes` is `nil`.
>> 
>> Backtrace:
>> 
>>   cl--assertion-failed((memq id track-changes--trackers))
>>   track-changes-fetch(nil #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_136>)
>>   eglot--track-changes-fetch(nil)
>>   eglot--signal-textDocument/didChange()
>>   eglot--request(#<eglot-lsp-server eglot-lsp-server-10d3578e408f> :shutdown nil :timeout 1.5)
>>   eglot-shutdown(#<eglot-lsp-server eglot-lsp-server-10d3578e408f>)
>>   eglot--managed-mode(-1)
>>   eglot--managed-mode-off()
>>   kill-current-buffer()
>>   funcall-interactively(kill-current-buffer)
>>   command-execute(kill-current-buffer)
>> 
>> Reproduction:
>> 
>> 1. Start emacs with `emacs -Q`.
>> 2. Run `M-: (setopt eglot-autoshutdown t) RET`
>> 3. Open any file you have an LSP server for and run `M-x eglot RET`.
>> 4. Kill the buffer.
>
> Thanks, I added Stefan and João to the discussion.

Btw, the corresponding (?) test fails as well:

--8<---------------cut here---------------start------------->8---
# make -C test eglot-tests
Test eglot-test-auto-shutdown backtrace:
  set-buffer(#<killed buffer>)
  (save-current-buffer (set-buffer buffer) (buffer-string))
  (princ (save-current-buffer (set-buffer buffer) (buffer-string)) 'ex
  (let ((buffer (car tail))) (eglot--test-message "contents of `%s':" 
  (while tail (let ((buffer (car tail))) (eglot--test-message "content
  (let ((tail buffers)) (while tail (let ((buffer (car tail))) (eglot-
  (cond (noninteractive (let ((tail buffers)) (while tail (let ((buffe
  (let ((buffers (delq nil (list (process-buffer (jsonrpc--process ser
  (progn (let ((buffers (delq nil (list (process-buffer (jsonrpc--proc
  (if (not test-body-successful-p) (progn (let ((buffers (delq nil (li
  (let ((server (car tail))) (if (jsonrpc-running-p server) (progn (co
  (while tail (let ((server (car tail))) (if (jsonrpc-running-p server
  (let ((tail new-servers)) (while tail (let ((server (car tail))) (if
  (let ((eglot-autoreconnect nil)) (let ((tail new-servers)) (while ta
  (unwind-protect (let ((eglot-autoreconnect nil)) (let ((tail new-ser
  (unwind-protect (let ((process-environment (cons (format "XDG_CONFIG
  (let* ((fixture-directory (make-nearby-temp-file "eglot--fixture-" t
  eglot--call-with-fixture((("project" ("thingy.c" . "int main() {retu
  (let (server buffer) (eglot--call-with-fixture '(("project" ("thingy
  #f(lambda () [typescript-mode-abbrev-table typescript-mode-syntax-ta
  #f(compiled-function () #<bytecode 0xe07b6c3d31b780b>)()
  handler-bind-1(#f(compiled-function () #<bytecode 0xe07b6c3d31b780b>
  ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
  ert-run-test(#s(ert-test :name eglot-test-auto-shutdown :documentati
  ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
  ert-run-tests((not (tag :unstable)) #f(compiled-function (event-type
  ert-run-tests-batch((not (tag :unstable)))
  ert-run-tests-batch-and-exit((not (tag :unstable)))
  eval((ert-run-tests-batch-and-exit '(not (tag :unstable))) t)
  command-line-1(("-L" ":." "-l" "ert" "--eval" "(setq treesit-extra-l
  command-line()
  normal-top-level()
Test eglot-test-auto-shutdown condition:
    (error "Selecting deleted buffer")
   FAILED   3/49  eglot-test-auto-shutdown (0.229999 sec) at lisp/progmodes/eglot-tests.el:344
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.