Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Q: Tweak makeprg #21

Open
vigilancer opened this issue Dec 3, 2018 · 9 comments
Open

Q: Tweak makeprg #21

vigilancer opened this issue Dec 3, 2018 · 9 comments

Comments

@vigilancer
Copy link

vigilancer commented Dec 3, 2018

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 vigilancer changed the title Tweak makeprg Q: Tweak makeprg Dec 3, 2018
@udalov
Copy link
Owner

udalov commented Dec 12, 2018

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
Copy link
Author

vigilancer commented Dec 12, 2018

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
Copy link
Owner

udalov commented Dec 12, 2018

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
Copy link
Author

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

@vigilancer
Copy link
Author

vigilancer commented Dec 12, 2018

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
Copy link
Owner

udalov commented Dec 12, 2018

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
Copy link
Author

vigilancer commented Dec 12, 2018

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

@udalov
Copy link
Owner

udalov commented Dec 12, 2018

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
Copy link
Author

This is really great, looking forward to it.

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

No branches or pull requests

2 participants