Skip to content

fix: attach doc comments to inner nodes in short-form if/elseif/else#1209

Merged
alexander-akait merged 1 commit intomainfrom
fix/short-form-if-doc-comment-placement
Mar 18, 2026
Merged

fix: attach doc comments to inner nodes in short-form if/elseif/else#1209
alexander-akait merged 1 commit intomainfrom
fix/short-form-if-doc-comment-placement

Conversation

@jorgsowa
Copy link
Copy Markdown
Collaborator

Fixes #1166

  1. Swap node("block") before next() — next() consumes : and simultaneously reads any following comments into _docs. By calling node("block") first (before : is eaten), those comments stay in _docs for the first inner node — e.g., a function — to claim as its own leadingComments. This makes the short-form if/elseif/else consistent with read_code_block and read_short_form, which already do node("block") before consuming {.
  2. noop injection for empty blocks — when a short-form block has no children but there are floating comments inside (between : and endif), a noop node is injected to absorb them as leadingComments. Without this, the comments had
    nowhere to attach and drifted to trailingComments on an unrelated node. Again, this aligns with read_code_block and read_short_form, which already had this guard.

Let me know if the second change is correct. The logic after the fix was not convincing to me, so I decided to align the behaviour for all blocks without children.

@jorgsowa jorgsowa self-assigned this Mar 17, 2026
@alexander-akait alexander-akait merged commit 1b4f88f into main Mar 18, 2026
6 checks passed
@alexander-akait alexander-akait deleted the fix/short-form-if-doc-comment-placement branch March 18, 2026 10:46
@czosel
Copy link
Copy Markdown
Collaborator

czosel commented Mar 22, 2026

Released in v3.5.0 🎉

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.

if{} and if..endif; cause function has wrong docblock (leadingComments)

3 participants