Search code examples
kotlinintellij-ideakdoc

How do I link to a top-level function in a KDoc comment?


Given a file com/example/Foo.kt

package com.example

fun bar() = null

If I try to link to it from KDoc:

/**
 * Used by [com.example.Foo.bar]
 */

Idea tells me "Cannot resolve symbol 'bar'"

/**
 * Used by [com.example.FooKt.bar]
 */

Idea now can't find "FooKt"


Solution

  • To link to a top-level function you need to use a proper FQDN, which is the package name and the element name (no matter what file it's defined in).

    E.g.

    /**
     * Used by [com.example.bar]
     */
    

    What has confused me initially is that if you use "Copy Reference" in Idea it will generate an incorrect value like com.example.FooKt.bar