Skip to content

Integrate the comment-preserving nf-lang formatter - #163

Open
ewels wants to merge 8 commits into
mainfrom
claude/language-server-formatter-integration-k2souq
Open

Integrate the comment-preserving nf-lang formatter#163
ewels wants to merge 8 commits into
mainfrom
claude/language-server-formatter-integration-k2souq

Conversation

@ewels

@ewels ewels commented Jul 16, 2026

Copy link
Copy Markdown
Member

Integrates the nf-lang formatter rework from nextflow-io/nextflow#7346 (merged, released as nf-lang 26.08.0-edge): comment preservation, multi-line string re-indentation, and the same refuse-to-format-on-comment-loss guard as nextflow lint. Updates the test suite accordingly.

Note: an earlier revision of this PR targeted the original, broader formatter overhaul (line wrapping via maxLineLength, fmt: directives, K&R style, blank-line normalization, include sorting). Those features were deferred to follow-up nf-lang PRs during review, so this PR was reworked to match the merged scope — the maxLineLength option and the tests pinning those features were removed.

Changes

nf-lang 26.08.0-edge

  • build.gradle bumps io.nextflow:nf-lang to 26.08.0-edge, the first release containing the merged formatter rework.

Comment collection at parse time

  • Comment collection is opt-in upstream: the script and config compiler configurations now set COMMENTS_OPTION, so every parse attaches the COMMENTS metadata the formatter needs. Without it, formatting silently drops every comment and the formatter's blank-line map degenerates (each line preceding a node counts as blank).

Safety guard

  • The shared FormattingProvider.commentsPreserved() helper uses the public Comments.textsOf(source, config) API: if formatting would remove or alter any comment, the provider shows an error and returns no edits — same behavior as nextflow lint -format.
  • Formatting an already-canonical document returns no edits instead of a byte-identical whole-document edit.

Code lens conversion

  • The typed-conversion previews (convertScriptToTyped/convertPipelineToTyped) no longer attach LEADING_COMMENTS metadata to synthesized params: the marker was removed upstream and comments now attach positionally per formatting pass. Converted params no longer carry their @Description comments — a known limitation of the conversion preview to revisit.
  • Verified that formatting synthesized/mutated ASTs through the new positional comment attacher neither crashes nor duplicates comments (pinned by a format-then-convert regression test).

Tests

  • Kept and passing: comment preservation (trailing, dangling, commented-out declarations), CRLF handling, multi-line string re-indentation, cached-AST idempotency (formatting the same cached AST repeatedly yields identical output), conversion regression tests, and hover-doc expectations (updated for the upstream docs moves).
  • Removed: tests pinning the deferred features (wrapping/maxLineLength, K&R, blank-line normalization, fmt: directives, include sorting).
  • Full suite: 264 tests, all passing except PluginSpecCacheTest in sandboxed environments without network egress (unrelated; passes in CI).

Issue closing

With the reduced upstream scope, only these language-server issues are fixed by this integration: #111, #116, #127, #140 (GitHub does not auto-close cross-repo references, so they need manual closing once this ships). The rest of the original list — #26, #54, #75, #115, #150, #153 — remain open, deferred to follow-up nf-lang PRs.

Release ordering

  1. Preserve comments in formatter nextflow#7346 merges (done, 2026-08-18)
  2. nf-lang release (done, 26.08.0-edge)
  3. This PR: language server integration
  4. Language server release
  5. Manually close Formatter removes commented out nextflow processes #111, Fix formatting of multi-line strings #116, Issue with formatting #127, Comment formatting and deletion upon saving #140

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb

claude added 8 commits July 16, 2026 12:59
…xtflow#7346)

Points the build at the nf-lang formatter overhaul from PR
nextflow-io/nextflow#7346, published to Maven local from the PR head
branch. This commit must be amended to the released nf-lang version
once the PR is merged and an nf-lang release exists — do not ship it
as-is.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
Expose the new nf-lang line-wrapping option as
nextflow.formatting.maxLineLength (default
FormattingOptions.DEFAULT_MAX_LINE_LENGTH = 120, 0 disables wrapping)
and pass it explicitly into every FormattingOptions construction, so
the language server never relies on the 5-arg constructor's implicit
default.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
…omment loss

Use the new 3-arg visitor constructors so comment reattachment always
sees exactly the buffer being formatted instead of re-reading the
SourceUnit. Adopt the same safety check as 'nextflow lint -format':
compare CommentReattacher.commentTexts before and after formatting and
refuse to return any edit if a comment would be removed or altered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
Pin the new canonical style at the language-server level: K&R if/else,
blank-line normalization, comment preservation (trailing, dangling and
commented-out declarations), line wrapping at the configured maximum
line length, and fmt: skip / fmt: off / fmt: on directives.

Add integration tests for the language-server trigger scenarios:

- formatting the same cached AST repeatedly without a document change
  produces identical output (comment metadata re-derivation must be
  idempotent)
- maxLineLength=0 disables line wrapping
- a file using fmt: off/on round-trips unchanged
- converting a script to static types after formatting the same cached
  AST neither crashes nor duplicates comments (the conversion formats
  freshly-built AST nodes that carry no reattached comment metadata)

The cached-AST tests write the file to disk first: the deferred
workspace scan re-scans from disk and would otherwise evict an
in-memory-only file from the AST cache between requests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
…ents

Pin the language-server-side behavior for the remaining formatter
issues closed by nextflow-io/nextflow#7346: include sorting under
sortDeclarations (#54), multi-line string re-indentation (#116), and
leading comments in CRLF files no longer merging with the following
code (#127).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
The Nextflow docs moved from nextflow.io/docs/latest to
docs.seqera.io/nextflow upstream, so the doc links baked into nf-lang
26.07.0-edge annotations changed accordingly. This change is durable:
it applies to any nf-lang release cut from current master, independent
of the formatter overhaul.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
- Extract the comment-preservation check into a shared
  FormattingProvider.commentsPreserved helper so the script and config
  providers no longer duplicate the safety-critical guard, and return
  no edits when the formatted text is unchanged instead of a
  whole-document no-op edit.
- Move the file-on-disk workaround for the deferred workspace scan
  into TestUtils (openOnDisk/deleteOnDisk) so the eviction rationale
  is documented once instead of in three test classes.
- Rebuild ConfigFormattingTest on the shared TestUtils harness instead
  of a private service-bootstrap clone.
- Collapse round-trip test cases onto checkRoundTrip helpers instead
  of pasting identical literals twice, and make the cached-AST tests
  use non-canonical input so a refused format cannot be mistaken for
  a no-op.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
nextflow-io/nextflow#7346 was merged in a reworked form scoped to
comment preservation and multi-line string re-indentation: comments
are now collected at parse time (opt-in via COMMENTS_OPTION) and
attached positionally per formatting pass, and the maxLineLength
option, fmt directives, K&R style, blank-line normalization, and
include sorting were deferred to follow-up PRs.

- Bump nf-lang to the released 26.08.0-edge (contains the merge).
- Enable COMMENTS_OPTION in the script and config compiler
  configurations so parses collect the comment metadata the
  formatter needs; without it every comment is dropped and the
  blank-line map degenerates (each preceding line counts as blank).
- Remove the maxLineLength option and wiring (deferred upstream).
- Revert the formatting visitors to the 2-arg constructors and port
  the refuse-to-format guard to Comments.textsOf.
- Drop the LEADING_COMMENTS metadata hack in the params conversion:
  the marker was removed and comments now attach positionally, so
  synthesized params no longer carry description comments (a known
  limitation of the conversion preview).
- Prune the tests pinning deferred features; keep comment
  preservation, CRLF handling, string re-indentation, cached-AST
  idempotency, and the conversion tests; update hover-doc links for
  the upstream stdlib-namespaces docs move.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6xXG4ocbea6AW3f9hYsJb
@ewels ewels changed the title Integrate the new nf-lang formatter (comment preservation, fmt directives, line wrapping) Integrate the comment-preserving nf-lang formatter Aug 22, 2026
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.

Formatter removes commented out nextflow processes

2 participants