Skip to content

scaladoc: indicate optional parameters with = ... #23676

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

katrinafyi
Copy link

currently, there is no indication in the scaladoc when parameters may be optional. this leads to long and overwhelming signatures 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 to learn which parameters are optional.

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:

// 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:
image

this might be related to #13424

@katrinafyi katrinafyi changed the title scaladoc: use ellipsis to indicate optional parameters in signatures scaladoc: indicate optional parameters with = ... Aug 6, 2025
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.
@katrinafyi katrinafyi force-pushed the optional-param-ellipses branch from bf0b9d1 to a7d9437 Compare August 6, 2025 23:33
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.

1 participant