fix: resolve the right formatter for each file - #880
Open
doorgan wants to merge 1 commit into
Open
Conversation
doorgan
force-pushed
the
doorgan/formatter-resolver
branch
from
September 3, 2026 05:33
84e0d00 to
3b8066b
Compare
doorgan
marked this pull request as ready for review
September 3, 2026 05:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#804 added a formatter cache, but it fails in the following scenarios:
Closing the first formatted file:
:no_formatterin the logsThis is because a.ex and b.ex will both point to the same entry in the cache. Removing a.ex will remove that path AND its entry, so the next time we request a formatter for b.ex, it will not find the old entry and the cache will return :no_formatter
This sharing of the formatter entry causes a second issue. Because they share the same entry and formatter function, any failure to format b.ex will point to a.ex, as that's the filename closed over by the formatter function in the entry cache:
This PR fixes both issues by changing the cache to track one formatter function per path, ensuring no formatter function is shared, and that closing a document won't break formatting for other files.
Note: it is very annoying that the formatter works by creating a bespoke function for each file, and that the formatter plugins don't seem to inherit the formatter options if we override them to set the right
:filefor each path, so this is what we have for now.