kotlin-language-server icon indicating copy to clipboard operation
kotlin-language-server copied to clipboard

Use without a build system

Open codic12 opened this issue 4 years ago • 15 comments

I am aware this is being worked on, but is there a branch we can compile to get it right now or something?

codic12 avatar Apr 04 '20 01:04 codic12

Should already work as of #154. Is kotlinc on your PATH?

fwcd avatar Apr 08 '20 00:04 fwcd

Yup! I'm using the vscode extension, it says stuff like println and readLine()!! is undefined (and asks me to add it to gradle)

codic12 avatar Apr 08 '20 01:04 codic12

:thinking: Any ideas on how to debug the problem?

codic12 avatar Apr 19 '20 03:04 codic12

Also btw, this is offtopic, but why isn't the atom extension maintained anymore? I would love to use this on atom as well

codic12 avatar Apr 19 '20 03:04 codic12

@gsbhasin123 Sure, is there anything not working with the Atom extension? It is updated independently from the language server.

fwcd avatar Apr 19 '20 14:04 fwcd

Oh, is it maintained? never mind then :sweat_smile:

Was wondering since the last commit was in august '19 and the last commit for Visual Studio Code's was just around 2 months ago

codic12 avatar Apr 19 '20 15:04 codic12

Yup! I'm using the vscode extension, it says stuff like println and readLine()!! is undefined (and asks me to add it to gradle)

For me, it only happened when I used snap to install it in ubuntu 20.04. No issue found when I manually downloaded the the kotlinc and added it to my $PATH

yaowenx avatar Jun 07 '20 17:06 yaowenx

ah. i can't check as i don't use kotlin anymore, sorry

codic12 avatar Jun 07 '20 17:06 codic12

ah. i can't check as i don't use kotlin anymore, sorry

No worries, just hope to help whoever is debugging this by posting it

yaowenx avatar Jun 07 '20 17:06 yaowenx

I also met this issue. Did you solve it?

lunw1024 avatar Jun 22 '20 08:06 lunw1024

no i don't do kotlin anymore.

codic12 avatar Jun 22 '20 23:06 codic12

If I'm following this thread properly, in order to write and run a kotlin file independently from the build systems, it looks like I need to put kotlinc in my PATH. I followed this guide here: [ https://kotlinlang.org/docs/tutorials/command-line.html ] to manually install the compiler and I downloaded the Kotlin zip from Github and only extracted the compiler folder. It also says to add the bin directory to the system path so I went and added the bin folder from the cli folder from the compiler folder I extracted to the ~/.bashrc file. I entered echo $PATH and it's there. but then I get this as a result...

sdkman kotlin install fail

If I remove the path I just added everything works fine. If I download kotlin via sdkman do I need to add kotlinc to my path? If not then how can I get a single kotlin file to work with the extension without the build system?

Roshadgu avatar Sep 07 '20 16:09 Roshadgu

it looks like I need to put kotlinc in my PATH. I followed this guide here: [ https://kotlinlang.org/docs/tutorials/command-line.html ] to manually install the compiler and I downloaded the Kotlin zip from Github and only extracted the compiler folder. It also says to add the bin directory to the system path so I went and added the bin folder from the cli folder from the compiler folder I extracted to the ~/.bashrc file. I entered echo $PATH and it's there. but then I get this as a result...

You mistakenly downloaded the source code for Kotlin. You need to download the runnable compiler instead (kotlin-compiler-*.zip).

mooffie avatar Nov 30 '20 14:11 mooffie

(Guys, make sure to "Open Folder"; see https://github.com/fwcd/vscode-kotlin/issues/56#issue-753527354.)

mooffie avatar Nov 30 '20 14:11 mooffie

I'm attempting to use Kotlin Language Server without a build system, using vim-lsp to edit standalone Kotlin files like

package foo

object FooMain {
	@JvmStatic
	fun main(args: Array<String>) {
		println("Hello ${args[0]}")
	}
}

This results in INCOMPATIBLE_CLASS errors all over the place, with log entries like

["<---",1,"kotlin-language-server",{"response":{"method":"textDocument/publishDiagnostics","jsonrpc":"2.0","params":{"uri":"file:///private/tmp/kotlin/foo.kt","diagnostics":[{"source":"kotlin","range":{"end":{"character":11,"line":3},"start":{"character":2,"line":3}},"code":"INCOMPATIBLE_CLASS","message":"Class 'kotlin.jvm.JvmStatic' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.1.15.\nThe class is loaded from /opt/local/share/java/kotlin/lib/kotlin-stdlib.jar!/kotlin/jvm/JvmStatic.class","severity":1},{"source":"kotlin","range":{"end":{"character":9,"line":5},"start":{"character":2,"line":5}},"code":"UNRESOLVED_REFERENCE","message":"Unresolved reference: println","severity":1},{"source":"kotlin","range":{"end":{"character":11,"line":3},"start":{"character":2,"line":3}},"code":"INCOMPATIBLE_CLASS","message":"Class 'kotlin.jvm.JvmStatic' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.1.15.\nThe class is loaded from /opt/local/share/java/kotlin/lib/kotlin-stdlib.jar!/kotlin/jvm/JvmStatic.class","severity":1}]}}}]

(The key message there is Class 'kotlin.jvm.JvmStatic' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.1.15.) kotlinc version 1.7.22-release-288 is installed via MacPorts in /opt/local/bin/kotlinc and is detected by the Kotlin LSP earlier in the log. It looks like in the absence of a gradle or maven build config it's defaulting to the lowest Kotlin language version, which is incompatible with the actual files included with the installation. I would expect, in the absence of a build system, to default the Kotlin language version to the version of kotlinc that's being used.

flwyd avatar Dec 29 '22 05:12 flwyd