udalov / kotlin-vim

Kotlin plugin for Vim. Featuring: syntax highlighting, basic indentation, Syntastic support
Apache License 2.0
632 stars 51 forks source link

Q: Tweak makeprg #21

Open vigilancer opened 5 years ago

vigilancer commented 5 years ago

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.

udalov commented 5 years ago

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)

vigilancer commented 5 years ago

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.

udalov commented 5 years ago

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.

vigilancer commented 5 years ago

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

vigilancer commented 5 years ago

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.

udalov commented 5 years ago

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.

vigilancer commented 5 years ago

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

udalov commented 5 years ago

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.

vigilancer commented 5 years ago

This is really great, looking forward to it.