Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Show how to configure auto-completion in IntelliJ #12

Open
sschuberth opened this issue Dec 21, 2021 · 7 comments
Open

Show how to configure auto-completion in IntelliJ #12

sschuberth opened this issue Dec 21, 2021 · 7 comments

Comments

@sschuberth
Copy link

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?

@ligee
Copy link
Contributor

ligee commented Jan 10, 2022

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.

@sschuberth
Copy link
Author

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 oss-review-toolkit/ort#4887.

@cottand
Copy link

cottand commented Mar 3, 2022

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

@sschuberth
Copy link
Author

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.

@gottagofaster236
Copy link

It works by 1) putting the definition into the separate module, and 2) include it as a dependency to the use-site module.

Is there a way to have autocompletion for standalone scripts outside a project?

@TWiStErRob
Copy link

TWiStErRob commented Sep 18, 2023

If by "standalone" you mean standard .main.kts files, we get "Apply Context" for those in the top right. I'm using IntelliJ IDEA 2023.2.2 Ultimate with Kotlin plugin 232-1.9.0.

@dpeter99
Copy link

dpeter99 commented Jan 4, 2024

Are there any updates on this? It would be instrumental to be able to offer code completion in projects where the build system is not gradle and the script files are being used as config for custom tooling. (only the final jar is present that has the scripting host)

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

No branches or pull requests

6 participants