[PR #1247] [MERGED] Format interpolated expressions as single line #966

Closed
opened 2025-12-30 01:27:59 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/apple/pkl/pull/1247
Author: @bioball
Created: 10/21/2025
Status: Merged
Merged: 10/24/2025
Merged by: @bioball

Base: mainHead: string-interpolation-formatting


📝 Commits (3)

  • a313e24 Format interpolated expressions as single line
  • cc4343e Fix formatting when leading/trailing comments are present
  • 2d22e09 Adjustments

📊 Changes

12 files changed (+355 additions, -126 deletions)

View changed files

📝 pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt (+222 -102)
📝 pkl-formatter/src/main/kotlin/org/pkl/formatter/Generator.kt (+0 -6)
📝 pkl-formatter/src/main/kotlin/org/pkl/formatter/ast/FormatNode.kt (+5 -7)
pkl-formatter/src/test/files/FormatterSnippetTests/input/single-line-strings.pkl (+7 -0)
pkl-formatter/src/test/files/FormatterSnippetTests/input/string-interpolation.pkl (+51 -0)
📝 pkl-formatter/src/test/files/FormatterSnippetTests/output/multi-line-strings.pkl (+1 -3)
pkl-formatter/src/test/files/FormatterSnippetTests/output/single-line-strings.pkl (+9 -0)
pkl-formatter/src/test/files/FormatterSnippetTests/output/string-interpolation.pkl (+52 -0)
📝 pkl-parser/src/main/java/org/pkl/parser/GenericParser.java (+3 -3)
📝 pkl-parser/src/main/java/org/pkl/parser/syntax/generic/NodeType.java (+1 -1)
📝 pkl-parser/src/test/kotlin/org/pkl/parser/GenericSexpRenderer.kt (+2 -2)
📝 pkl-parser/src/test/kotlin/org/pkl/parser/SexpRenderer.kt (+2 -2)

📄 Description

This forces iterpolated expressions to be single-line, so that newline literals within the bounds of two string delimiters can be seen as verbatim newlines in the resulting string.

Edge case: in the case of a line comment, it's not possible to keep this as a single line expression.
These are kept as multi-line expressions.

Also:

  • Remove ForceWrap, this node is not used.
  • Rename StringConstant -> StringChars

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/apple/pkl/pull/1247 **Author:** [@bioball](https://github.com/bioball) **Created:** 10/21/2025 **Status:** ✅ Merged **Merged:** 10/24/2025 **Merged by:** [@bioball](https://github.com/bioball) **Base:** `main` ← **Head:** `string-interpolation-formatting` --- ### 📝 Commits (3) - [`a313e24`](https://github.com/apple/pkl/commit/a313e2410261a166fd63cf950d36b2d398269b90) Format interpolated expressions as single line - [`cc4343e`](https://github.com/apple/pkl/commit/cc4343e3d41261a400a9af1c2a57f2a91c9bb290) Fix formatting when leading/trailing comments are present - [`2d22e09`](https://github.com/apple/pkl/commit/2d22e09ff62e51b6a0305e05b61430f461263b47) Adjustments ### 📊 Changes **12 files changed** (+355 additions, -126 deletions) <details> <summary>View changed files</summary> 📝 `pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt` (+222 -102) 📝 `pkl-formatter/src/main/kotlin/org/pkl/formatter/Generator.kt` (+0 -6) 📝 `pkl-formatter/src/main/kotlin/org/pkl/formatter/ast/FormatNode.kt` (+5 -7) ➕ `pkl-formatter/src/test/files/FormatterSnippetTests/input/single-line-strings.pkl` (+7 -0) ➕ `pkl-formatter/src/test/files/FormatterSnippetTests/input/string-interpolation.pkl` (+51 -0) 📝 `pkl-formatter/src/test/files/FormatterSnippetTests/output/multi-line-strings.pkl` (+1 -3) ➕ `pkl-formatter/src/test/files/FormatterSnippetTests/output/single-line-strings.pkl` (+9 -0) ➕ `pkl-formatter/src/test/files/FormatterSnippetTests/output/string-interpolation.pkl` (+52 -0) 📝 `pkl-parser/src/main/java/org/pkl/parser/GenericParser.java` (+3 -3) 📝 `pkl-parser/src/main/java/org/pkl/parser/syntax/generic/NodeType.java` (+1 -1) 📝 `pkl-parser/src/test/kotlin/org/pkl/parser/GenericSexpRenderer.kt` (+2 -2) 📝 `pkl-parser/src/test/kotlin/org/pkl/parser/SexpRenderer.kt` (+2 -2) </details> ### 📄 Description This forces iterpolated expressions to be single-line, so that newline literals within the bounds of two string delimiters can be seen as verbatim newlines in the resulting string. Edge case: in the case of a line comment, it's not possible to keep this as a single line expression. These are kept as multi-line expressions. Also: * Remove `ForceWrap`, this node is not used. * Rename `StringConstant` -> `StringChars` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 01:27:59 +01:00
adam closed this issue 2025-12-30 01:27:59 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#966