kotlin-script-examples icon indicating copy to clipboard operation
kotlin-script-examples copied to clipboard

Show how to configure auto-completion in IntelliJ

Open sschuberth opened this issue 3 years ago • 7 comments

Could you please extend the examples to also make auto-completion, e.g. in hello-kotlinx-html.scriptwithdeps.kts, work in IntelliJ?

For example, if I'm extending ScriptWithMavenDeps with a dummy property like

abstract class ScriptWithMavenDeps {
    val dummy: String = "oink"
}

what does it take to offer dummy when typing this. in hello-kotlinx-html.scriptwithdeps.kts?

sschuberth avatar Dec 21 '21 14:12 sschuberth

It's a bit complicated and also the area where we're going to change thing soon, so we'll update the description later, but for an example what works now, you may have a look at simple-main-kts here. It works by 1) putting the definition into the separate module, and 2) include it as a dependency to the use-site module. A possible quirk is that you may need to compile the definition module and then reload the project in IntelliJ to make it work.

ligee avatar Jan 10 '22 08:01 ligee

you may need to compile the definition module and then reload the project in IntelliJ to make it work.

That's indeed one of the (undocumented) pitfalls I ran into, but I eventually got it working in https://github.com/oss-review-toolkit/ort/pull/4887.

sschuberth avatar Jan 10 '22 08:01 sschuberth

Hi I am also looking to get autocompletion going in a custom script inside IntelliJ. Is this still up to date? The current KEEP mentions something about extra gradle config with the kotlinScriptDef configuration. I am not seeing that anywhere here

cottand avatar Mar 03 '22 00:03 cottand

extra gradle config with the kotlinScriptDef configuration. I am not seeing that anywhere here

For the record, I'm also not using the kotlinScriptDef configuration in https://github.com/oss-review-toolkit/ort but still auto-completion works for the file at https://github.com/oss-review-toolkit/ort/blob/main/examples/evaluator-rules/src/main/resources/example.rules.kts.

I guess you only need the kotlinScriptDef configuration if your project does not anyway depend (via the implementation configuration) on the module that contains the script definitions.

sschuberth avatar Apr 05 '22 06:04 sschuberth