Skip to content

Backport "scaladoc: indicate optional parameters with = ..." to 3.3 LTS #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2025

Conversation

tgodzik
Copy link

@tgodzik tgodzik commented Aug 12, 2025

Backports scala#23676 to the 3.3.7.

PR submitted by the release tooling.

katrinafyi and others added 3 commits August 12, 2025 20:34
currently, there is no indication in the scaladoc when parameters may be
optional. this leads to [long and overwhelming signatures][1] which is
not at all user-friendly. users are forced to first intuit that this
method *might* have some optional parameters, then manually find [the
source code][2] to learn which parameters are optional.

[1]:
https://javadoc.io/static/com.lihaoyi/os-lib_3/0.11.5/os/proc.html#call-fffff910
[2]:
https://github.com/com-lihaoyi/os-lib/blob/0.11.5/os/src/ProcessOps.scala#L192-L205

this PR suffixes `= ...` after the type signature of optional
parameters. this makes it possible to tell that these parameters are
optional and may be omitted.

this applies to both method parameters and class parameters. the format
is intentionally similar to the definition of such optional parameters
in code:
```scala
// new scaladoc display:
def f(x: Int, s: String = ...): Nothing

// code:
def f(x: Int, s: String = "a"): Nothing
```
of course, the `...` term is different. i think this is a reasonable
choice because (1) ellipsis commonly represents something present but
omitted, and (2) it is not valid Scala, so there is no risk someone will
think this is denoting a literal default value of `...`. a proper
ellipsis character (rather than 3 periods) could also be considered, but
i found that looked out of place amongst the monospace signature.

about displaying the default value itself, this PR does not display the
default value. this is because of anticipated difficulties around
displaying an expression. this could be re-visited in future, but i
think it should not hold up this PR. i believe that this PR alone is
already a substantial improvement for the documentation of optional
parameters.

finally, here is a screenshot of the scaladoc from the new
optionalParams.scala test case:
<img width="663" height="646" alt="image"
src="https://github.com/user-attachments/assets/870410ee-0535-484b-84c8-8b683464471e"
/>

this might be related to scala#13424
currently, there is no indication in the scaladoc when parameters may be
optional. this leads to [long and overwhelming signatures][1] which is
not at all user-friendly. users are forced to first intuit that this
method *might* have some optional parameters, then manually find [the
source code][2] to learn which parameters are optional.

[1]:
https://javadoc.io/static/com.lihaoyi/os-lib_3/0.11.5/os/proc.html#call-fffff910
[2]:
https://github.com/com-lihaoyi/os-lib/blob/0.11.5/os/src/ProcessOps.scala#L192-L205

this PR suffixes `= ...` after the type signature of optional
parameters. this makes it possible to tell that these parameters are
optional and may be omitted.

this applies to both method parameters and class parameters. the format
is intentionally similar to the definition of such optional parameters
in code:
```scala
// new scaladoc display:
def f(x: Int, s: String = ...): Nothing

// code:
def f(x: Int, s: String = "a"): Nothing
```
of course, the `...` term is different. i think this is a reasonable
choice because (1) ellipsis commonly represents something present but
omitted, and (2) it is not valid Scala, so there is no risk someone will
think this is denoting a literal default value of `...`. a proper
ellipsis character (rather than 3 periods) could also be considered, but
i found that looked out of place amongst the monospace signature.

about displaying the default value itself, this PR does not display the
default value. this is because of anticipated difficulties around
displaying an expression. this could be re-visited in future, but i
think it should not hold up this PR. i believe that this PR alone is
already a substantial improvement for the documentation of optional
parameters.

finally, here is a screenshot of the scaladoc from the new
optionalParams.scala test case:
<img width="663" height="646" alt="image"
src="https://github.com/user-attachments/assets/870410ee-0535-484b-84c8-8b683464471e"
/>

this might be related to scala#13424
[Cherry-picked d240468][modified]
Base automatically changed from backport-lts-3.3-23664 to lts-3.3 August 13, 2025 13:05
@tgodzik
Copy link
Author

tgodzik commented Aug 13, 2025

No regressions detected in the community build up to backport-lts-3.3-23676.

Reference

@tgodzik tgodzik merged commit 7e360b9 into lts-3.3 Aug 13, 2025
22 checks passed
@tgodzik tgodzik deleted the backport-lts-3.3-23676 branch August 13, 2025 13:05
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.

2 participants