Skip to content

Brainstorming: kscript plugin for intellij #148

Open

Description

@holgerbrandl

convert //DEPS to file:DependsOn (and same of other annotations)

E.g. if script is using:

@file:DependsOn("de.mpicbg.scicomp:kutils:0.8.4")
but pom/gradle is indicating just

compile "de.mpicbg.scicomp:kutils:0.8.3"
the script line should be tagged with a warning such as

Mismatch between script and project dependencies.

suggestion to add shebang line

create temp-project from context menu

More tricky

run configuration

Activity

  1. oshai commented on Aug 15, 2018

    @oshai
    Contributor

    Run configuration will be great (ie the arrow to run files from inside)
    I also struggle with stacktraces so mapping to the project source-files will be great.
    It will also be great to have a template for new projects, maybe with multi-modules like I discussed in #149

  2. jfftonsic commented on Jan 29, 2019

    @jfftonsic

    Hi, just a question, does anyone know if the current state of things is the following?

    • you can open idea with kscript --idea script.kts
    • the code completion works with the dependencies you've added
    • there exists a Run option for the script
    • the run fails because even with the imports and the editor detecting it correctly, the run doesn't seem to detect it
  3. holgerbrandl commented on Jan 30, 2019

    @holgerbrandl
    CollaboratorAuthor

    Via the --idea path, it should work like that. But you need a rather recent version of IDEA. And debugging of kotlin scripts is not yet support by the IDE in general.

  4. jfftonsic commented on Jan 30, 2019

    @jfftonsic

    Ok. But I'm actually using the community 2019.x latest EAP/RC/etc. So something may be missconfigured here, or new idea broke some integration. But thanks for the response.

  5. holgerbrandl commented on Jan 31, 2019

    @holgerbrandl
    CollaboratorAuthor

    The community edition should be fine. Could you post a small example which I could use to reproduce the problem?

  6. jfftonsic commented on Jan 31, 2019

    @jfftonsic
    #!/usr/bin/env kscript
    
    //DEPS com.beust:klaxon:0.24
    //DEPS com.github.kittinunf.fuel:fuel:1.3.1
    //DEPS org.jetbrains.kotlin:kotlin-reflect:1.3.11
    //DEPS org.jetbrains.kotlin:kotlin-stdlib:1.3.11
    //DEPS org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
    
    
    import com.github.kittinunf.fuel.Fuel
    
    Fuel.get("https://httpbin.org/get")
            .response { request, response, result->
                println(request)
                println(response)
                val (bytes, error) = result
                if (bytes != null) {
                    println("[response bytes] ${String(bytes)}")
                }
            }
    

    I am not being able to upload images here (it says Something went really wrong ...)

    The IDE autocomplete works.

    But the result of the Kotlin script run configuration execution is

    /usr/java/jdk1.8.0_144/bin/java -javaagent:/home/jtonsic/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-1/191.4738.6/lib/idea_rt.jar=38878:/home/jtonsic/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-1/191.4738.6/bin -Dfile.encoding=ISO-8859-1 -classpath /home/jtonsic/.IdeaIC2019.1/config/plugins/Kotlin/kotlinc/lib/kotlin-compiler.jar:/home/jtonsic/.IdeaIC2019.1/config/plugins/Kotlin/kotlinc/lib/kotlin-reflect.jar:/home/jtonsic/.IdeaIC2019.1/config/plugins/Kotlin/kotlinc/lib/kotlin-stdlib.jar:/home/jtonsic/.IdeaIC2019.1/config/plugins/Kotlin/kotlinc/lib/kotlin-script-runtime.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -kotlin-home /home/jtonsic/.IdeaIC2019.1/config/plugins/Kotlin/kotlinc -script /home/jtonsic/workspace/incident-analyser/apagar2.kts
    apagar2.kts:10:12: error: unresolved reference: github
    import com.github.kittinunf.fuel.Fuel
               ^
    apagar2.kts:12:1: error: unresolved reference: Fuel
    Fuel.get("https://httpbin.org/get")
    ^
    apagar2.kts:13:21: error: cannot infer a type for this parameter. Please specify it explicitly.
            .response { request, response, result->
                        ^
    apagar2.kts:13:30: error: cannot infer a type for this parameter. Please specify it explicitly.
            .response { request, response, result->
                                 ^
    apagar2.kts:13:40: error: cannot infer a type for this parameter. Please specify it explicitly.
            .response { request, response, result->
                                           ^
    
    Process finished with exit code 1
    

    Now that I read the command executed, I saw that the execution did not put the extra deps in the classpath. However it seems that there is no option in the run configuration itself. There is an option to set the script templates classpath inside idea->Settings->...->kotlin compiler. However (again), even if I manually add something there, it is ignored at the execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions