Skip to content

Support Kotlin context parameters #4011

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

Closed
atyrin opened this issue Jan 28, 2025 · 2 comments · Fixed by #4080
Closed

Support Kotlin context parameters #4011

atyrin opened this issue Jan 28, 2025 · 2 comments · Fixed by #4080
Assignees
Labels
enhancement An issue for a feature or an overall improvement language: Kotlin Issue/PR related to the Kotlin language feature/analysis/docs
Milestone

Comments

@atyrin
Copy link
Contributor

atyrin commented Jan 28, 2025

The feature still experimental till Kotlin 2.3.
https://github.com/Kotlin/KEEP/blob/context-parameters/proposals/context-parameters.md

Dokka 2.0.0 in K1 and K2 modes ignores the presence of the context parameters in code.

@atyrin atyrin added enhancement An issue for a feature or an overall improvement language: Kotlin Issue/PR related to the Kotlin language feature/analysis/docs labels Jan 28, 2025
@fzhinkin
Copy link

Dokka 2.0.0 in K1 and K2 modes ignores the presence of the context parameters in code.

I'd say things a bit worse: Dokka ignores all the documentation written for functions w/ ctx params and emits an "empty" pages for such functions.

For a declaration like this:

package org.example

/**
 * That's a contextual function!
 *
 * @return nothing.
 */
context(_: Int)
public fun contextual() {
}

you'll get a page like this:
Image

Without a proper support from Dokka, it's unclear how to publish documentation for Stdlib part of the ctx params: https://youtrack.jetbrains.com/issue/KT-72866

@whyoleg
Copy link
Collaborator

whyoleg commented Mar 18, 2025

Initial implementation for context parameters, which is covered by this issue, should support:

  1. Showing context parameters in Dokka signatures (functions, properties)
context(a: A, _: B, _: C)
val property: String

context(type: T)
fun <T: CharSequence> withGeneric()
  1. Context parameters in lambdas signatures (functions, properties)
fun accept(param: context(X) () -> String)

fun returns(): (context(X) () -> String)

Additional notes:

  • Constructors are not allowed to have context parameters (currently)
  • Context parameter have no default value (comparing to ordinary parameters)
  • Overloads with/without context parameters and with different context parameters

For the next step: #4065

@whyoleg whyoleg added this to the Dokka 2.1.0 milestone Mar 18, 2025
@vmishenev vmishenev self-assigned this Mar 30, 2025
@vmishenev vmishenev linked a pull request Apr 4, 2025 that will close this issue
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 language: Kotlin Issue/PR related to the Kotlin language feature/analysis/docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants