Search code examples
kotlinkotlin-dokka

How to document a primary constructor parameter with Kotlin Dokka


Let's say there's a class which primary constructor has the parameter param that I'd like to be resolved (linked to the actual parameter) within the doc block of the class.

/** Class A does something using [param]. 
@constructor constructs A with [param].
*/
class A (param: Int)

However, the inscription param is highlighted by the IDE saying that it cannot resolve symbol param.


Solution

  • Actually, dokka correctly finds the parameter if you reference it with [param] in the @constructor paragraph, you can check that by inspecting the URL that appears in the assembled docs, which looks like:

    file:///.../some.package/-a/-init-.html#some.package.A$<init>(kotlin.Int)/param
    

    Seemingly, the warning about an unresolved reference is an issue with the IDE support for KDoc. Please report it at kotl.in/issue.

    Another option is to use @param in the class KDoc:

    /** 
     * Class A does something using [param]. 
     * @param param means something special.
    */
    class A (param: Int)