Skip to content
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

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

Open
CeruleanW opened this issue Nov 29, 2023 · 1 comment

Comments

@CeruleanW
Copy link

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
Copy link
Author

Sample code: Playground.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant