Skip to content

Run cljr-rename-file-or-dir asynchronously - #597

Merged
bbatsov merged 1 commit into
masterfrom
async-rename-file
Jul 12, 2026
Merged

bbatsov merged 1 commit into
masterfrom
async-rename-file

Conversation

@bbatsov

@bbatsov bbatsov commented Jul 12, 2026

Copy link
Copy Markdown
Member

First of the async conversions from the command audit. Renaming a file updates references to it across the whole project, which can be slow, and until now it blocked Emacs on a synchronous middleware round-trip. It now returns immediately and finishes (the completion message, ast-cache warming, revisiting the affected buffers) in a callback once the middleware responds.

The reusable bit is cljr--call-middleware-async-collect - the non-blocking counterpart to cljr--call-middleware-sync: it accumulates the response messages, and when the request is done reports any middleware error to the user (instead of letting it escape the nREPL process filter) and hands the result to the callback. There's a generous safety-net timeout so a hung request or dropped connection doesn't leave a command waiting forever.

Validated live against a real refactor-nrepl connection: the command returns immediately, then renames the file, updates its ns, and rewrites a requiring file's :require when the middleware responds. Buttercup covers the accumulation helper (split value/done messages, value+done together, not firing before done).

Note on scope: after mapping the remaining synchronous calls, this is the cleanest high-value async target. Most of the others are either fast/cached (not worth it), act at point (async would jump the user's cursor), or are entangled with the just-added preview flow (would mean re-restructuring fresh code) - so I stopped here rather than sweep them all. The helper is in place if we want to convert more later.

Renaming a file rewrites references to it across the whole project, which
can take a while. It used a blocking cljr--call-middleware-sync, freezing
Emacs until the middleware responded. It now fires the request through a
new cljr--call-middleware-async-collect helper and does the rest - the
completion message, ast-cache warming, revisiting affected buffers - in
the callback, so Emacs stays responsive.

cljr--call-middleware-async-collect is the non-blocking counterpart to
cljr--call-middleware-sync: it accumulates the response messages, and on
done reports any middleware error to the user (rather than letting it
escape the nREPL process filter) and hands the result to the callback. A
generous safety-net timeout keeps a hung request from waiting forever.

Validated live against a real refactor-nrepl connection: the command
returns immediately, then renames the file, updates its ns, and rewrites
a requiring file's :require once the middleware responds.
@bbatsov
bbatsov merged commit 6a0cf1d into master Jul 12, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant