doomemacs / doomemacs/core

Code formatting broken in eglot-managed buffers

Open
#7,972 3 comments 1 reaction 0 assignees View on GitHub
is:bug needs-triage
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### I confirm that...

- [X] I have searched the [issue tracker](https://github.com/doomemacs/doomemacs/issues), [documentation](https://docs.doomemacs.org), [FAQ](https://docs.doomemacs.org/-/faq), [Discourse](https://discourse.doomemacs.org), and [Google](https://google.com), in case this issue has already been reported/resolved.

- [X] I have read "[How to Debug Issues](https://doomemacs.org/d/how2debug)", and will use it to provide as much information about this issue as possible.

- [X] The issue can be reproduced on the **latest** available commit of Doom.

- [X] The issue can be reproduced on a stable release of Emacs, such as 27, 28, or 29. *(Unstable versions end in .50, .60, or .9x)*

### Expected behavior

When I invoke `(+format/region-or-buffer)` (by pressing `SPC c f`) in a Eglot-managed buffer I expect the code to be formatted.

### Current behavior

Pressing `SPC c f` results in `(cl-assertion-failed ((memq id track-changes--trackers) nil))` error. Running it in debug mode produces the following backtrace: https://pastebin.com/yqHBXyRA

To summarise what's happening:

1. `eglot--signal-textDocument/didChange()` invokes `(eglot--track-changes-fetch eglot--track-changes)`,
2. `eglot--track-changes-fetch(id)` invokes `(track-changes-fetch id func)`,
3. `track-changes-fetch(id func)` asserts and fails `(cl-assert (memq id track-changes--trackers))`

Now, `eglot--track-changes` is non-nil in the buffer, and indeed, running just `M-x eglot-format-buffer` (without the surrounding apheleia machinery) works.

After some debugging I traced it down to `apheleia--run-formatter-function` in `apheleia/apheleia-formatters.el:1110`, which executes the formatter with a scratch buffer, thus losing the buffer-local `eglot--track-changes`.

### Steps to reproduce

Press `SPC c f` in a Eglot-managed buffer.

### System Information

https://pastebin.com/tM4xmxBn

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.