-
Notifications
You must be signed in to change notification settings - Fork 363
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
Resolution of links to extensions in KDoc #385
Comments
I'm not sure this is on-topic for this KEEP, but I'd very much like to see a way to disambiguate links of different things that have the same name. For example, when a class and a top-level function exist, it is not currently possible to create a link that refers to one of them specifically. Unlike regular function overloads, which are all listed on the same page, so the disambiguation isn't particularly needed, homonyms on different pages hinder the documentation quality at the moment. |
Hey @CLOVIS-AI, this is known and tracked in https://youtrack.jetbrains.com/issue/KT-19765/KDoc-Provide-ability-disambiguate-links-to-classes-vs-links-to-functions |
We should describe the substitution more precisely. The definition here is quite mathematical (as opposed to algorithmic), which has the problem that the search space might be very large. When the compiler compiles a callable reference in code, the reference already has its type arguments set. Hence, it's quite easy to check them against the expected type parameters. On the other hand, a type reference in KDoc does not have its type arguments set. So there needs to be another mechanism to match the type reference against the extension function's extension receiver. To make sure that there can be a proper and well performing implementation, I think the KEEP should describe the algorithm which matches the type references against the declared extension receiver. (Maybe I got a bit carried away, but what follows is my attempt at such an algorithm.) Naive instantiationLet's say we have an extension function KDoc reference For covariant type parameters interface Animal
class Cat : Animal
class Type<out A : Animal>
fun Type<Cat>.extension() { }
/** [Type.extension] */
fun documented() { } If we instantiate The crucial point, as the proposal notes, is that the type parameter can be substituted with some concrete type to make the receiver type fit. So there is some instantiation of Possible approachI wonder if the following approach suffices. First, let's assume we have the following code: interface T<A_0, A_1, ..., A_TN>
class S<B_0, B_1, ..., B_SN> : T<...> // Not pictured: Indirect inheritance.
fun T<E_0, E_1, ..., E_I>.extension() { }
/** [S.extension] */
fun documented() { } We check that
The description might not be complete, but it may be a direction to go in. Or maybe there are other similar approaches somewhere in the compiler or language specification. Exampleinterface Animal
class Cat : Animal
interface Shape
class Ball : Shape
interface Container<out A, X, Y>
class AnimalContainer<out AC_A : Animal, out AC_X : String> : Container<AC_A, AC_X, String>
class ShapeContainer<out SC_A : Shape, out SC_X : Int> : Container<SC_A, SC_X, Int>
fun <FUN_X : String> Container<Cat, FUN_X, String>.extension() { } For the KDoc reference
For the KDoc reference
|
This is an issue to discuss Resolution of links to extensions in KDoc. The full text of the proposal is here.
During the migration of Dokka analysis to K2, several questions arose around KDoc links resolution.
In particular, it was unclear how a link to an extension should be resolved in the presence of type parameters.
Link resolution in KDoc is not fully specified, and for this reason some cases are currently implemented
differently in K1 and K2 analysis.
The goal of the proposal is to try to describe consistent rules on how KDoc links to extensions should be resolved.
The text was updated successfully, but these errors were encountered: