Skip to content

Conversation

Forostovec
Copy link
Contributor

Fix #11836

Problem: In multi-variable declarations (DeclMulti), empty tuple slots are represented as None, so they lack span information. Without spans, the formatter cannot anchor comments between commas for uninitialized positions, causing comments to merge, drift, or be misplaced.

Solution: Compute synthetic per-slot spans for the tuple LHS by scanning the source between the ( of the declaration and the start of the initializer =. Split at top-level commas (skipping nested parens and comments) to derive a span for each slot, including empty ones. Pass these spans to the list/tuple printer so print_comments can correctly place comments even when the slot has no variable.

@0xrusowsky
Copy link
Contributor

First of all thanks for the PR!

Despite the solution is pragmatic and it works, imo it doesn't make sense for the formatter to have to parse source code that solar has already processed.

Instead we should do a PR upstream to solar, and then use the spans (hence why i had the issue labelled as "blocked by solar" in the meta ticket).

Note that users can always disable the formatter in that code block.

With that being said though, i'll defer the decision of whether to accept the proposed fix or not to @DaniPopes and @grandizzy

@DaniPopes DaniPopes closed this Sep 29, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

bug(fmt): unable to place comments with uninitialized vars
3 participants