Skip to content

Not sure how to install Lsp Server for kotlin mode. #900

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

Closed
nedijahij opened this issue Jun 21, 2019 · 14 comments
Closed

Not sure how to install Lsp Server for kotlin mode. #900

nedijahij opened this issue Jun 21, 2019 · 14 comments

Comments

@nedijahij
Copy link

I am trying to use kotlin lsp mode and i cannot make it work in kotlin mode. After install kotlin mode, then i tried to install kotlin server using npm but seem like it is not an npm package and now i could not figure out what should i do. Please give some instruction to install lsp server for kotlin.

@yyoncho
Copy link
Member

yyoncho commented Jun 21, 2019

The instructions on how to obtain the language server, linked from lsp-mode README are here: https://github.com/fwcd/KotlinLanguageServer

@yyoncho yyoncho closed this as completed Jun 21, 2019
@mcraveiro
Copy link

mcraveiro commented Jul 10, 2019

Hi @yyoncho,

I managed to start the Kotlin server from the instructions above, but the problem is I can't seem to "link" it to emacs. I get the error:

LSP :: No LSP server for kotlin-mode.

Is there a document specifying how to point emacs to the LSP server?

Thanks for your time.

Marco

@yyoncho
Copy link
Member

yyoncho commented Jul 10, 2019

@mcraveiro Check *lsp-log*. You will see what lsp-mode is looking for.

In your case something like that would do the job:

  (add-to-list 'exec-path "~/kotlin-language-server/bin")

For other servers, we usually have a variable which can be used to point lsp-mode to the server location.

@mcraveiro
Copy link

mcraveiro commented Jul 10, 2019

Thanks @yyoncho. The log file says:

Command "kotlin-language-server" is not present on the path.
Command "kotlin-language-server" is not present on the path.

Also, I think also my problem is the name of the server; I have a script called local/KotlinLanguageServer-0.1.13/bin/server.sh. I'll try to update the server name too.

@mcraveiro
Copy link

Also, for what its worth, I found a lsp-kotlin project [1].

[1] https://github.com/whily/lsp-kotlin

@mcraveiro
Copy link

mcraveiro commented Jul 11, 2019

Ok, I've made some progress but not quite out of the woods yet. So now my *lsp-log* says:

Command "kotlin-language-server" is present on the path.
Found the following clients for SOME_FILE/HelloTest.kt: (server-id kotlin-ls, priority -1)
The following clients were selected based on priority: (server-id kotlin-ls, priority -1)

However, the server fails to start. In *kotlin-ls::stderr*, I see:

/usr/bin/emacs: PATH/local/KotlinLanguageServer-0.1.13/bin/kotlin-language-server: Exec format error

Process kotlin-ls stderr finished
/usr/bin/emacs: /home/marco/local/KotlinLanguageServer-0.1.13/bin/kotlin-language-server: Exec format error

I wonder if this is anything to do with the fact that kotlin-language-server is a bash script? The interesting thing is that running it from M-! works:

openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-post-Debian-5)
OpenJDK 64-Bit Server VM (build 11.0.3+7-post-Debian-5, mixed mode, sharing)
Content-Length: 103

{"jsonrpc":"2.0","id":"1","method":"workspace/configuration","params":{"items":[{"section":"kotlin"}]}}Content-Length: 108

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"main      Connected to client"}}Content-Length: 118

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"client    System.in has closed, exiting"}}

The plot thickens...

@mcraveiro
Copy link

Ah actually, just a very very silly emacs user! :-) forgot to put the hash bang in shell script! For anyone else who may be looking for a script to start the kotlin server, mine is now as follows (kotlin-language-server):

#!/bin/bash
DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
APP_HOME=${DIRNAME}/..

# Add default JVM options here. You can also use JAVA_OPTS and
# SERVER_OPTS to pass JVM options to this script.
JAVA_EXE=/usr/bin/java
${JAVA_EXE} -version

CLASSPATH=${APP_HOME}/lib/server-0.1.13.jar:${APP_HOME}/lib/j2k-1.3.11-release-272.jar:${APP_HOME}/lib/kotlin-plugin-1.3.11-release-272.jar:${APP_HOME}/lib/shared.jar:${APP_HOME}/lib/org.eclipse.lsp4j-0.5.0.jar:${APP_HOME}/lib/org.eclipse.lsp4j.generator-0.5.0.jar:${APP_HOME}/lib/org.eclipse.xtend.lib-2.17.0.jar:${APP_HOME}/lib/org.eclipse.xtend.lib.macro-2.17.0.jar:${APP_HOME}/lib/org.eclipse.xtext.xbase.lib-2.17.0.jar:${APP_HOME}/lib/guava-21.0.jar:${APP_HOME}/lib/kotlin-compiler-1.3.11.jar:${APP_HOME}/lib/kotlin-reflect-1.3.11.jar:${APP_HOME}/lib/fernflower-1.0.jar:${APP_HOME}/lib/kotlin-stdlib-1.3.11.jar:${APP_HOME}/lib/org.eclipse.lsp4j.jsonrpc-0.5.0.jar:${APP_HOME}/lib/kotlin-script-runtime-1.3.11.jar:${APP_HOME}/lib/kotlin-stdlib-common-1.3.11.jar:${APP_HOME}/lib/annotations-13.0.jar:${APP_HOME}/lib/gson-2.7.jar

# Execute server
"${JAVA_EXE}" -classpath "${CLASSPATH}" org.javacs.kt.MainKt

I used the packages directly from the official github project [1], which may be a tad old.

[1] https://github.com/fwcd/KotlinLanguageServer/releases

@yyoncho
Copy link
Member

yyoncho commented Jul 11, 2019

@mcraveiro so you are good?

As a side note, it would be good if we do the server downloading automatically - so if you are interested in contributing to lsp-mode you may give it a try. Here it is a PR for lsp-python-ms - emacs-lsp/lsp-python-ms#37 .

@mcraveiro
Copy link

@yyoncho I have managed to get the kotlin server to connect to emacs, but now my problem is that I am getting errors that I do not see when I manually run gradle. I shall investigate those, and then update this ticket with a full set of instructions on how to get kotlin working. I will also look into the PR above and see how hard it is to integrate it all. If it is within my limited skillset, I'll open a PR :-) Thanks for your help.

@dj8yfo
Copy link

dj8yfo commented Jul 12, 2019

@yyoncho kotlin lsp kind of starts, but it's not too useful. *Messages*:

LSP :: Connected to [kotlin-ls:10236 status:starting].
error in process filter: while: Symbol’s value as variable is void: spacemacs-jump-handlers-kotlin-mode
error in process filter: Symbol’s value as variable is void: spacemacs-jump-handlers-kotlin-mode
LSP :: Internal error. [6 times]
No jump handler was able to find this symbol.

@yyoncho
Copy link
Member

yyoncho commented Jul 12, 2019

@gisochre

Do (spacemacs|define-jump-handlers 'kotlin-mode)

@dj8yfo
Copy link

dj8yfo commented Jul 13, 2019

@yyoncho thanks. That helped, lsp-mode became mostly functional 👍

@mcraveiro
Copy link

mcraveiro commented Jul 16, 2019

Actually, I'm still struggling to get KLS to work correctly, though I do not think its an emacs problem. I've taken it to the KLS developers [1]. I'll update this ticket once I get to the bottom of it. Thanks a lot for your help.

[1] fwcd/kotlin-language-server#126

@mcraveiro
Copy link

OK, I've done a lot of faffing with this and whilst I am not yet done, my intermediate notes may be helpful to anyone trying to get Kotlin Language Server (KLS) to work.

Limitations

Whilst KLS seem to work fine for regular Kotlin code, bear in mind the following limitations:

  1. As stated in many other places, you need Java 8 to build KLS itself (lsp-ocaml #125, Make parsing even faster, and use less memory #108, Calculate wrong end position after kill a line #114). You can use the existing binaries [1], saving you from having to install Java 8, but there have been a fair number of commits since then.
  2. Kotlin DSL files are not supported by KLS. ([Discussion] Fix incremental #124) Best disable LSP mode for these or else you will get a lot of errors.
  3. You can use a recent version of Java to build your projects (such as Java 11) and it seems to work fine. However, KLS is set to 1.6 internally, which causes a lot of noise with warnings etc. If you apply this patch [2] and rebuild KLS it will set it to 1.8, removing most of the annoying Java version warnings.
  4. Adding new dependencies (jars) to a project appears to require a restart of KLS when used under emacs (lsp-restart-workspace).

Setup

Both the build from the git repo and the binaries have a script called server in the bin dir, whereas lsp-mode is looking for kotlin-language-server. I fixed this the lazy way:

$ cp server kotlin-language-server 

I was also told to put the new directory on the path, e.g.:

(add-to-list 'exec-path "~/local/KotlinLanguageServer-20190716/bin")

After this KLS works fine for me.

HTH.

[1] https://github.com/fwcd/KotlinLanguageServer/releases/tag/0.1.13
[2] fwcd/kotlin-language-server#72 (comment)

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

4 participants