google / google/google-java-format

Conditional OpenOp / CloseOp

未關閉
#556 2 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Java
星號
6.2k
分支
937
平均合併
6 分鐘
30 天內合併 PR
3

描述

In `ktfmt`, I'd like to format the following:

```
fun longName() = coroutineScope {
foo()
//
}
```

but if it doesn't fit in a single line, I'd like to get

```
fun longName() =
coroutineScope {
foo()
//
}
```

I only managed to create the first form by _not_ wrapping the lambda in an `OpenOp` / `CloseOp` block, while the second form arises naturally from such a block around `coroutine { … }`.

One way to solve this is to create a conditional `OpenOp` / `CloseOp`, similarly to `Indent.If`, and then emit a block that materializes only if there had been a break after the `=`.

What do you think?

(I admit this isn't super clear, let me know if I should make another attempt at explaining this)

cc @cushon @bethcutler

貢獻指南

開啟貢獻指南

研究方向

首先追蹤 formatter 對 OpenOp 和 CloseOp 的處理,然後將其與 Indent.If 進行比較。重現 coroutineScope 範例,並確認等號後的換行如何影響縮排。完成的標準是緊湊形式和換行形式都能正確產生,並且有測試涵蓋此行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
tooling
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。