kotlin-vim icon indicating copy to clipboard operation
kotlin-vim copied to clipboard

Q: Tweak makeprg

Open vigilancer opened this issue 6 years ago • 9 comments

How do you feel about adding support for appropriate makeprg into this plugin? Something like this should do:

:setlocal makeprg=java\ -cp\ .:/usr/local/Cellar/kotlin/1.3.10/libexec/lib/kotlin-stdlib.jar\ %:r:gs?^.?\\u&?Kt

( % filename :r remove extension gs?^.?\\u&? - capitalise first letter (hello - Hello) - same as in /^./\u&/gs Kt - add to the end )

This will cover scripts without specified package: :!java -cp .:/usr/local/Cellar/kotlin/1.3.10/libexec/lib/kotlin-stdlib.jar HelloKt

But sure this can be extended with something like :echo substitute(getline(1), ‘package ‘, ‘’, ‘’).

I'm not totally clear on how to get kotlin stdlib path. We can try to guess it or require user to set env variable to the kotlin install dir.

vigilancer avatar Dec 03 '18 13:12 vigilancer

Do you maybe mean launching kotlin-compiler.jar in makeprg instead of kotlin-stdlib.jar? Because to run the program, you must first compile it with kotlinc (or with java .../kotlin-compiler.jar)

udalov avatar Dec 12 '18 11:12 udalov

When I enable this plugin and open kotlin file in vim it takes care about compiling .kt file into .class file (with Kt suffix).

If I create hello.kt with content:

fun main(args: Array<String>) {
   println("Hello!!")
}

and open it in vim (with kotlin-vim enabled) there will be compiled class file:

 % tree -L 2
.
├── HelloKt.class
├── META-INF
│   └── main.kotlin_module
└── hello.kt

What I propose is to simplify running this class with :make command.

vigilancer avatar Dec 12 '18 11:12 vigilancer

it takes care about compiling .kt file into .class file

What do you mean by this? There's no code in this plugin that invokes the Kotlin compiler, which makes me wonder how exactly are you getting .class files without launching the compiler manually.

udalov avatar Dec 12 '18 12:12 udalov

Something compiling it alright. It happens if filetype is set to kotlin. Let me investigate.

vigilancer avatar Dec 12 '18 12:12 vigilancer

~~Butler~~ Linter did it. My mistake, kotlin-vim have nothing to do with it apart from setting filetype to kotlin. Seems w0rp/ale is too smart. We don't want to rely on linter to compile, do we. Okay, then we can extend original idea and add compilation command into makerg too.

vigilancer avatar Dec 12 '18 12:12 vigilancer

OK, thanks for the clarification.

I would actually wait until KT-27171 is implemented, at which point the burden of deciding how is the executable file named and in what package it lies will be completely on the kotlin command line script, and the kotlin-vim plugin can simply invoke kotlin %. We can also require that the kotlin script name can be resolved when running it via the shell (i.e. it must exist in PATH) and avoid looking up the Kotlin installation path manually.

udalov avatar Dec 12 '18 13:12 udalov

Yes, this should fit the bill. That feature strikes me as more elegant solution. Merely wondering are there any estimates?

vigilancer avatar Dec 12 '18 13:12 vigilancer

I don't have any estimates at this point, since we've only started planning 1.4/1.3.x recently and we don't know the complete picture of what's to be done yet. I can only say that I am personally encouraged by the possibility of a more user-friendly Kotlin CLI, and will do my best to implement KT-27171 as soon as I have an opportunity, at the very least to improve my own UX when working with Kotlin.

udalov avatar Dec 12 '18 13:12 udalov

This is really great, looking forward to it.

vigilancer avatar Dec 12 '18 13:12 vigilancer