Skip to content
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

Support documenting context parameters #4065

Open
whyoleg opened this issue Mar 18, 2025 · 0 comments
Open

Support documenting context parameters #4065

whyoleg opened this issue Mar 18, 2025 · 0 comments
Labels
enhancement An issue for a feature or an overall improvement kdoc-spec An issue that requires clarification from the KDoc spec's perspective

Comments

@whyoleg
Copy link
Collaborator

whyoleg commented Mar 18, 2025

Currently it's possible to document function parameters via @param and receiver of function/property via @receiver:

/**
 * @receiver documentation for receiver of type [String]
 * @param number documentation for parameter with name [number]
 */
fun String.test(number: Int)

The same should be possible for context parameters.

There are two options on how it could work:

  1. new tag @context - context parameters have a separate tag, similar to receiver. As context parameters have different meaning, and most likely should be represented in different section of documentation - separate from Parameters section, it might make sense to have separate tag. In this case receiver, function parameters and context parameters will have three different tags.
/**
 * @context scope documentation for context parameter
 * @receiver documentation for receiver of type [String]
 * @param number documentation for parameter with name [number]
 */
context(scope: Scope)
fun String.test(number: Int)
  1. reusing @param - context parameters are treated similar to ordinary parameters. But it's still make sense to show them separately in documentation.
/**
 * @param scope documentation for context parameter
 * @receiver documentation for receiver of type [String]
 * @param number documentation for parameter with name [number]
 */
context(scope: Scope)
fun String.test(number: Int)

Bonus (questionable) option: use @param for referencing both context parameters, function parameters and receiver. In KDoc it's possible to use [this] to reference receiver of function/property in the way it's possible to reference named parameters in documentation:

/**
 * when calling function, [this] should be longer than [number] symbols
 */
fun String.test(number: Int)

With this possibility in mind, it could be possible to replace @receiver tag with @param this:

/**
 * @param scope documentation for context parameter
 * @param this documentation for receiver of type [String]
 * @param number documentation for parameter with name [number]
 */
context(scope: Scope)
fun String.test(number: Int)

Or with brackets:

/**
 * @param[scope] documentation for context parameter
 * @param[this] documentation for receiver of type [String]
 * @param[number] documentation for parameter with name [number]
 */
context(scope: Scope)
fun String.test(number: Int)

In this case @receiver tag could be deprecated (or gradually phased out) and both referencing and documenting receiver will have same syntax

@whyoleg whyoleg added enhancement An issue for a feature or an overall improvement kdoc-spec An issue that requires clarification from the KDoc spec's perspective labels Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An issue for a feature or an overall improvement kdoc-spec An issue that requires clarification from the KDoc spec's perspective
Projects
None yet
Development

No branches or pull requests

1 participant