kotlin-compiler-server icon indicating copy to clipboard operation
kotlin-compiler-server copied to clipboard

Support completion hints for type-safe builders inferences in *.kts files

Open CeruleanW opened this issue 2 years ago • 2 comments

Description

The auto-completion feature in the Kotlin Compiler Server does not support type-safe builders when used in a standalone context outside of a function, which is the scenario for *.kts files. This is particularly noticeable with DSLs.

Expected Behavior

Auto-completion should work consistently for type-safe builders, e.g. HTML builders, both within functions and in standalone usage. This would significantly improve the development experience, especially when working with DSLs.

Current Behavior

While auto-completion works correctly within a function scope, it fails to provide proper suggestions or hints for standalone type-safe builders without a main function.

Steps to Reproduce

Use a type-safe HTML builder within a function and observe the functioning auto-completion. Use the same builder in a standalone context. Notice the lack of auto-completion hints.

Example


package html

// Inside a function - auto-completion works
fun main() {
    html {
        head {
            title { +"HTML encoding with Kotlin" }
        }
    }
}

// Standalone - auto-completion does not work
html {
    head {
        title { +"HTML encoding with Kotlin" }
    }
}

class HTML() : TagWithText("html") {
    fun head(init: Head.() -> Unit) = initTag(Head(), init)
    val sampleValue = 222
}

// [Rest of the provided code for Element, TextElement, Tag, etc.]

In the above example, the auto-completion feature assists with the html builder when used inside the main function but does not provide assistance for the standalone html builder.

Snipaste_2023-11-29_09-57-19 Snipaste_2023-11-29_09-58-14

CeruleanW avatar Nov 29 '23 15:11 CeruleanW

Sample code: Playground.txt

CeruleanW avatar Nov 29 '23 15:11 CeruleanW