Skip to content

don't emit organize-imports code action when result is identical#3177

Open
akhilesharora wants to merge 2 commits intozigtools:masterfrom
akhilesharora:fix-organize-imports-noop-edits
Open

don't emit organize-imports code action when result is identical#3177
akhilesharora wants to merge 2 commits intozigtools:masterfrom
akhilesharora:fix-organize-imports-noop-edits

Conversation

@akhilesharora
Copy link
Copy Markdown

@akhilesharora akhilesharora commented Apr 16, 2026

When imports are already organized, source.organizeImports still returned insert + delete edits whose net effect is no change. Clients apply them anyway, which dirties the buffer, adds to the undo stack, and flickers virtual text diagnostics. The reporter notes gopls returns no edits in this case.

This builds the organize edits, applies them to the source in memory, and skips emitting the code action when the result equals the original text. Happy to switch to a structural check instead if that's preferred. Went with apply and compare because it seemed simpler to reason about.

Added a test with three already organized shapes that asserts no source.organizeImports action is returned; it fails on master and passes here. Also ran the built binary against the exact source from the issue as a sanity check.

Fixes #2523

The source.organizeImports code action always emitted insert + delete
edits whose net effect was no change, causing editor undo-stack churn
and diagnostic flicker on already-organized files.

Apply the generated edits in-memory and suppress the action if the
resulting source matches the original.

Fixes zigtools#2523
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.

source.organizeImports code action sends edits even when none are necessary

1 participant