Git Product home page Git Product logo

kotlin-language-server's Introduction

Kotlin Language Server

Release Build Downloads Chat

A language server that provides smart code completion, diagnostics, hover, document symbols, definition lookup, method signature help and more for Kotlin.

Icon

Any editor conforming to LSP is supported, including VSCode and Atom.

Getting Started

Packaging

Packaging status

This repository needs your help!

The original author created this project while he was considering using Kotlin in his work. He ended up deciding not to and is not really using Kotlin these days though this is a pretty fully-functional language server that just needs someone to use it every day for a while and iron out the last few pesky bugs.

There are two hard parts of implementing a language server:

  • Figuring out the dependencies
  • Incrementally re-compiling as the user types

The project uses the internal APIs of the Kotlin compiler.

Figuring out the dependencies

Dependencies are determined by the DefaultClassPathResolver.kt, which invokes Maven or Gradle to get a list of classpath JARs. Alternatively, projects can also 'manually' provide a list of dependencies through a shell script, located either at [project root]/kls-classpath or [config root]/kotlin-language-server/classpath, which outputs a list of JARs. Depending on your platform, the scripts also can be suffixed with .{sh,bat,cmd}.

  • Example of the ~/.config/kotlin-language-server/classpath on Linux:
#!/bin/bash
echo /my/path/kotlin-compiler-1.4.10/lib/kotlin-stdlib.jar:/my/path/my-lib.jar
  • Example of the %HOMEPATH%\.config\kotlin-language-server\classpath.bat on Windows:
@echo off
echo C:\my\path\kotlin-compiler-1.4.10\lib\kotlin-stdlib.jar;C:\my\path\my-lib.jar

Incrementally re-compiling as the user types

I get incremental compilation at the file-level by keeping the same KotlinCoreEnvironment alive between compilations in Compiler.kt. There is a performance benchmark in OneFilePerformance.kt that verifies this works.

Getting incremental compilation at the expression level is a bit more complicated:

  • Fully compile a file and store in CompiledFile:
    • val content: String A snapshot of the source code
    • val parse: KtFile The parsed AST
    • val compile: BindingContext Additional information about the AST from typechecking
  • After the user edits the file:
    • Find the smallest section the encompasses all the user changes
    • Get the LexicalScope encompassing this region from the BindingContext that was generated by the full-compile
    • Create a fake, in-memory .kt file with just the expression we want to re-compile
      • Add space at the top of the file so the line numbers match up
    • Re-compile this tiny fake file

The incremental expression compilation logic is all in CompiledFile.kt. The Kotlin AST has a built-in repair API, which seems to be how IntelliJ works, but as far as I can tell this API does not work if the surrounding IntelliJ machinery is not present. Hence I created the "fake tiny file" incremental-compilation mechanism, which seems to be quite fast and predictable.

There is an extensive suite of behavioral tests, which are all implemented in terms of the language server protocol, so you should be able to refactor the code any way you like and the tests should still work.

Modules

Name Description
server The language server executable
shared Classpath resolution and utilities

Scripts

Name Command Description
release_version.py python3 scripts/release_version.py Creates a tag for the current version and bumps the development version

Protocol Extensions

The Kotlin language server supports some non-standard requests through LSP. See KotlinProtocolExtensions for a description of the interface. The general syntax for these methods is kotlin/someCustomMethod.

Initialization Options

The Kotlin language server supports some custom initialization options via the initializationOptions property in the initialize request parameters. See InitializationOptions in Configuration for a list of supported properties.

Features

Autocomplete

Autocomplete

Signature help

Signature Help

Hover

Hover

Go-to-definition, find all references

Find all references

Document symbols

Document symbols

Global symbols

Global symbols

Authors

kotlin-language-server's People

Contributors

a-stewart avatar arturbosch avatar chenrui333 avatar daplf avatar deltatre-johann avatar donniewest avatar dtsuzuku-ibm avatar elamcsquared avatar fwcd avatar gayanper avatar georgewfraser avatar goooler avatar henryhchchc avatar jeremylcarter avatar jlahoda avatar jonas-w avatar koush avatar ks-korovina avatar kuro46 avatar markov avatar mtdl9 avatar nycto avatar renfraser avatar skirwan avatar strum355 avatar svermeulen avatar themkat avatar tony-sol avatar wikoion avatar yuk1ty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlin-language-server's Issues

Fail to start the KotlinLanguageServer

I downloaded the KotlinLanguageServer from VSCode Extension tab in VSCode. It working in the KotlinQuickStart project, but not mine.

My project hierarchy are simarly to following:
.
├── README.md
├── build.gradle
├── docs
├── gradle
│ └── wrapper
├── gradle.properties
├── gradlew
├── gradlew.bat
├── kotlin_project_a kotlin project a
│ ├── bin
│ ├── build
│ ├── build.gradle
│ ├── config
│ └── src
├── frontend
├── settings.gradle
├── src kotlin project b
├── main
└── test

I am not sure if it is because I have multiple kotlin project within the same repository.

Supper non-JVM backends (Kotlin/Native, Kotlin/JS, Kotlin/Wasm)

Support non-JVM backends, such as...

The native backend might be particularly interesting for iOS/Android apps using Compose Multiplatform, while the JS/Wasm support would be cool for using Kotlin in (web) frontend projects.

The kotlin-compiler-server used by the kotlin-playground (hosted on https://play.kotlinlang.org), provides a nice reference implementation for JS and Wasm and would be worth studying.

Since the language server itself (mostly) just depends on the compiler frontend, integrating dependency resolution would be the central challenge.

Auto-import of global symbols

Show all global (including unimported) symbols in code completion lists and import them automatically when chosen (similar to vscode-java). This would require querying the classpath without slowing down the language server too much.

A easy-to-use delivery of Language Server

At some point, I'd like to investigate support for this LS in Eclipse IDE and/or Eclipse Che.
To achieve that, it's usually much easier if the LS providers a distribution that can be embedded in an Eclipse plugin or a Docker image without all the burden of doing a build.
So it would be helpful if the project ships such easy to consume distribution.

Decompiler

Include or add support for decompiled source code since raw bytecode is not very readable in UTF-8:

image

Issues with primitive type classes

Whenever I attempt to use the 'String' class, it shows it as one of a couple errors shown below.

This is when I call the String class, like for declaring parameters
This is when I call the String class, like for declaring parameters

This is when I call a Java function that takes a String as a parameter
This is when I call a Java function that takes a String as a parameter

My project builds just fine with Gradle, and it happens on all my dozens of file.. I have not edited anything for a couple weeks and came back to work on it and saw this.

Language Server - possible default packages missing?

This occurs on both MacOSX (when working) and Windows - so I think this is an issue in the language server and not the VSCode extension. In VSCode it raises a number of issues, which seem to indicate that it is missing the default packages or that it isn't finding them.

Steps to repro in VSCode windows; create a file with the following content.

package yo

fun main(args:Array<String>) {
    println("This is a wonderful extension")
}

Check the problems window and see the following, related to this issue:

Unresolved reference: Array
Unresolved reference: println
...
This class shouldn't be used in Kotlin. Use kotlin.String instead.

If I compile & run, it executes just fine. Anything we can do for this?

It might also be a resolution issue, since if I do import kotlin.* or import kotlin.io.* they do not resolve in VSCode either but they run fine.

Multiple declarations bug

The problem is that all Kotlin sources are parsed in the repository which may include temporary copies in build folders too. This leads to redeclaration errors across the entire workspace.

To adress this issue, the respective build folders (bin, target, build, ...) have to be excluded from the language server parser. I have already tried using a filter in SourceFiles.findSourceFiles(...), though unsuccessfully.

The Kotlin Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

I have just installed this extension in VS Code Insiders 1.26.0 on a Windows 10 x64 machine. However, when opening Kotlin projects, I get the message I put in the title. The Kotlin output window only shows this:

[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Error - 9:52:56 AM] Connection to server got closed. Server will not be restarted.

And when looking in DevTools, I see this:

ERR Message header must separate key and value using :: Error: Message header must separate key and value using :
    at C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:68:23
    at Array.forEach (<anonymous>)
    at MessageBuffer.tryReadHeaders (C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:65:17)
    at StreamMessageReader.onData (C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:194:43)
    at Socket.<anonymous> (C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:185:19)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

That message is repeated 4 or 5 times in fast succession. Any solutions to this?

C:\Users\Noah\Desktop\kotlin> java -version
  java version "1.8.0_151"
  Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
  Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

C:\Users\Noah\Desktop\kotlin> kotlin -version
  Kotlin version 1.2.60-eap-75 (JRE 1.8.0_151-b12)

Server initialization failed.

Environment: Ubuntu 16.04, JDK 8.

First of all, I am using Monaco editor which shares a common core with VS Code, although it's not officially supported by Kotlin Language Server (KLS).

I have installed/built KLS with no issue. Next I use the KotlinQuickStart project to experiment with KLS. The project is in /sbin/KotlinQuickStart. After I have started the Monaco editor in the browser, it sends a JSON-RPC request to the server like this:

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"rootPath":null,"rootUri":"file:///sbin/KotlinQuickStart/src/main/kotlin","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true},"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":false},"symbol":{"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":true}},"textDocument":{"synchronization":{"dynamicRegistration":true},"completion":{"completionItem":{"snippetSupport":true},"dynamicRegistration":true},"hover":{"dynamicRegistration":true},"signatureHelp":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"definition":{"dynamicRegistration":true},"codeAction":{"dynamicRegistration":true},"codeLens":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true}}},"initializationOptions":{"storagePath":"/","gocodeCompletionEnabled":true},"trace":"off"}}

KLS doesn't send a response, and I see a Server initialization failed error in the browser console quickly. I try to view the log produced by KLS, but I am unable to find any.

Any chance you could provide some help on this or some instructions on how to view KLS' log, so that I can dig deeper?

Thanks!

VSCode Extension - Internal Error

After resolving my previous issues (19 and 20), the extension seems to just randomly stop responding; either just doesn't work or offers suggestions for a few and then stops. No error message though the following does appear in the developer tools.

	at new ResponseError (/Users/rmaclean/.vscode/extensions/fwcd.kotlin-0.1.3/node_modules/vscode-jsonrpc/lib/messages.js:46:28)
	at handleResponse (/Users/rmaclean/.vscode/extensions/fwcd.kotlin-0.1.3/node_modules/vscode-jsonrpc/lib/main.js:430:48)
	at processMessageQueue (/Users/rmaclean/.vscode/extensions/fwcd.kotlin-0.1.3/node_modules/vscode-jsonrpc/lib/main.js:258:17)
	at Immediate.<anonymous> (/Users/rmaclean/.vscode/extensions/fwcd.kotlin-0.1.3/node_modules/vscode-jsonrpc/lib/main.js:242:13)
	at runCallback (timers.js:672:20)
	at tryOnImmediate (timers.js:645:5)
	at processImmediate [as _immediateCallback] (timers.js:617:5)

If I take the code and build it myself and run it in debug it works just fine. I even built the extension manually and installed it, but then it stopped working again so it seems to be something about the communication between the language server and extension which talk fine when debugging but not when running normally.

The above all relate to my Mac; I have gotten this to reproduce on my Windows machine as well, by opening a folder. It seems happy if I just open a single file on Windows but haven't tried to that on MacOS or tried debugging the extension on Windows.

Any ideas or experiments I can run for you?

Kotlin formatter

We can't reformat our code. Maybe we can use ktlint

There is no document formatter for 'kotlin'-files installed.

Unmatched Parenthesis parse errors outside expressions are not always reported

There are some parse errors, caused by unmatched parenthesis or braces outside expressions, that are not reported by the server diagnostics.

For example starting with this valid file:

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

If an open parenthesis, closed parenthesis or closed brace is added at the end of the file, no error is reported. For example adding these characters triggers no errors:

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

With open braces instead an error is correctly reported at the start of the line

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

Couldn't start client Kotlin Language Server on Windows 10

Hey there!
I've installed the extension from the market on a windows 10 pc and after setting up the env variable for the JDk and kotlin everything went smoothly. But when I went ahead and install the extension on my main PC I got this notification ,,Couldn't start client Kotlin Language Server" even after setting up the env variables under PATH.
The only log that I get is the following:
[Error - 7:41:05 PM] Starting client failed Launching server using command c:\Users\Adrian\.vscode\extensions\fwcd.kotlin-0.1.8\build\install\kotlin-language-server\bin\kotlin-language-server.bat failed.

I've already reinstalled the extension and reset the env vars. When I went to check the path from the log to see if there is a problem with that script I realized that there is no build directory which is obviously the source of the error.

Can anyone help me out please?

Java and Kotlin cannot refer to each other

Now, I have a project in which some class of Java import some class of Kotlin and some class of Kotlin import some class of Java. It not work. There are many errors and red line on screen.
And I try to "Go to definition" which is a class by downloading in maven, which in kotlin class, not successed.

How can I resolve it?

Diagnostics false negatives

I have the following line (from this repo) return Hover(listOf(Either.forRight(MarkedString("kotlin", hoverText) for which KLS reports:

[INFO]      debounce0   main    Linting .../hover/hovers.kt
[INFO]      async0      main    Finished in 11 ms
[INFO]      debounce0   main    No diagnostics in hovers.kt
[INFO]      async0      main    Find symbols in TextDocumentIdentifier [
                                uri = "file:///home/noah/Kotlin/KotlinLanguageServer/src/main/kotlin/org/javacs/kt/hover/hovers.kt"
                                ]    

while gradle complains:
e: /home/noah/Kotlin/KotlinLanguageServer/src/main/kotlin/org/javacs/kt/hover/hovers.kt: (51, 74): Expecting ')'

Java to Kotlin converter fails in AnnotationConverter

java.lang.NullPointerException
	at org.jetbrains.kotlin.j2k.AnnotationConverter.<init>(AnnotationConverter.kt:31)
	at org.jetbrains.kotlin.j2k.Converter.<init>(Converter.kt:60)
	at org.jetbrains.kotlin.j2k.Converter.<init>(Converter.kt:40)
	at org.jetbrains.kotlin.j2k.Converter$Companion.create(Converter.kt:71)
	at org.jetbrains.kotlin.j2k.JavaToKotlinConverter$elementsToKotlin$intermediateResults$1.invoke(JavaToKotlinConverter.kt:109)
	at org.jetbrains.kotlin.j2k.JavaToKotlinConverter$elementsToKotlin$intermediateResults$1.invoke(JavaToKotlinConverter.kt:48)
	at org.jetbrains.kotlin.j2k.JavaToKotlinConverter$WithProgressProcessor$processItems$1.run(JavaToKotlinConverter.kt:258)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:543)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:488)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
	at org.jetbrains.kotlin.j2k.JavaToKotlinConverter$WithProgressProcessor.processItems(JavaToKotlinConverter.kt:248)
	at org.jetbrains.kotlin.j2k.JavaToKotlinConverter.elementsToKotlin(JavaToKotlinConverter.kt:108)
	at org.jetbrains.kotlin.j2k.JavaToKotlinConverter.elementsToKotlin(JavaToKotlinConverter.kt:94)
	at org.javacs.kt.javaToKotlin.JavaToKotlinConverterKt.convertJavaToKotlin(javaToKotlinConverter.kt:54)
	at org.javacs.kt.KotlinWorkspaceService.executeCommand(KotlinWorkspaceService.kt:40)
	... 16 more

This null pointer might be caused by an incompatible kotlin-converter.jar version. Unfortunately, the JetBrains/kotlin/j2k module has not been published to Maven central, which makes it hard to optain a current version of this dependency.

Concurrency issues while linting

The language server sometimes runs into concurrency issues, because the async and debounce-0 threads are linting simultaneously. After throwing a ConcurrentModificationException, code completion fails although both threads keep running.

org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: Exception while analyzing expression at (9,15) in ~/git/KotlinLanguageServer/src/main/kotlin/org/javacs/kt/formatter/KotlinFormatter.kt
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:233)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:211)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:91)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:161)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:145)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeOfLastExpressionInBlock(ExpressionTypingServices.java:336)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getBlockReturnedTypeWithWritableScope(ExpressionTypingServices.java:277)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getBlockReturnedType(ExpressionTypingServices.java:194)
	at org.jetbrains.kotlin.types.expressions.FunctionsTypingVisitor.computeUnsafeReturnType(FunctionsTypingVisitor.kt:248)
	at org.jetbrains.kotlin.types.expressions.FunctionsTypingVisitor.computeReturnType(FunctionsTypingVisitor.kt:213)
	at org.jetbrains.kotlin.types.expressions.FunctionsTypingVisitor.visitLambdaExpression(FunctionsTypingVisitor.kt:157)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.visitLambdaExpression(ExpressionTypingVisitorDispatcher.java:249)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher$ForDeclarations.visitLambdaExpression(ExpressionTypingVisitorDispatcher.java:44)
	at org.jetbrains.kotlin.psi.KtLambdaExpression.accept(KtLambdaExpression.java:39)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:172)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:91)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:161)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:132)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:119)
	at org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver.getFunctionLiteralTypeInfo(ArgumentTypeResolver.java:300)
	at org.jetbrains.kotlin.resolve.calls.GenericCandidateResolver.addConstraintForFunctionLiteralArgument(GenericCandidateResolver.kt:479)
	at org.jetbrains.kotlin.resolve.calls.GenericCandidateResolver.completeTypeInferenceDependentOnFunctionArgumentsForCall(GenericCandidateResolver.kt:361)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.completeTypeInferenceDependentOnFunctionLiterals(CallResolver.java:628)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.doResolveCallOrGetCachedResults(CallResolver.java:600)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.lambda$computeTasksAndResolveCall$0(CallResolver.java:207)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:91)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.computeTasksAndResolveCall(CallResolver.java:205)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.computeTasksAndResolveCall(CallResolver.java:195)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.resolveFunctionCall(CallResolver.java:320)
	at org.jetbrains.kotlin.resolve.calls.CallExpressionResolver.getResolvedCallForFunction(CallExpressionResolver.kt:93)
	at org.jetbrains.kotlin.resolve.calls.CallExpressionResolver.getCallExpressionTypeInfoWithoutFinalTypeCheck(CallExpressionResolver.kt:215)
	at org.jetbrains.kotlin.resolve.calls.CallExpressionResolver.getUnsafeSelectorTypeInfo(CallExpressionResolver.kt:330)
	at org.jetbrains.kotlin.resolve.calls.CallExpressionResolver.getSafeOrUnsafeSelectorTypeInfo(CallExpressionResolver.kt:362)
	at org.jetbrains.kotlin.resolve.calls.CallExpressionResolver.getQualifiedExpressionTypeInfo(CallExpressionResolver.kt:449)
	at org.jetbrains.kotlin.types.expressions.BasicExpressionTypingVisitor.visitQualifiedExpression(BasicExpressionTypingVisitor.java:709)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.visitQualifiedExpression(ExpressionTypingVisitorDispatcher.java:370)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher$ForDeclarations.visitQualifiedExpression(ExpressionTypingVisitorDispatcher.java:44)
	at org.jetbrains.kotlin.psi.KtVisitor.visitDotQualifiedExpression(KtVisitor.java:302)
	at org.jetbrains.kotlin.psi.KtDotQualifiedExpression.accept(KtDotQualifiedExpression.kt:31)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:172)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:91)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:161)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:132)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:144)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:114)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:93)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getType(ExpressionTypingServices.java:130)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.safeGetType(ExpressionTypingServices.java:79)
	at org.jetbrains.kotlin.resolve.VariableTypeAndInitializerResolver.resolveInitializerType(VariableTypeAndInitializerResolver.kt:155)
	at org.jetbrains.kotlin.resolve.VariableTypeAndInitializerResolver.access$resolveInitializerType(VariableTypeAndInitializerResolver.kt:25)
	at org.jetbrains.kotlin.resolve.VariableTypeAndInitializerResolver$resolveTypeNullable$1.invoke(VariableTypeAndInitializerResolver.kt:84)
	at org.jetbrains.kotlin.resolve.VariableTypeAndInitializerResolver$resolveTypeNullable$1.invoke(VariableTypeAndInitializerResolver.kt:25)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:354)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:410)
	at org.jetbrains.kotlin.types.DeferredType.getDelegate(DeferredType.java:78)
	at org.jetbrains.kotlin.resolve.BodyResolver.computeDeferredType(BodyResolver.java:957)
	at org.jetbrains.kotlin.resolve.BodyResolver.resolveProperty(BodyResolver.java:718)
	at org.jetbrains.kotlin.resolve.BodyResolver.resolvePropertyDeclarationBodies(BodyResolver.java:750)
	at org.jetbrains.kotlin.resolve.BodyResolver.resolveBehaviorDeclarationBodies(BodyResolver.java:116)
	at org.jetbrains.kotlin.resolve.BodyResolver.resolveBodies(BodyResolver.java:241)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:225)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations$default(LazyTopDownAnalyzer.kt:60)
	at org.javacs.kt.Compiler.compileFiles(Compiler.kt:138)
	at org.javacs.kt.SourcePath.compileFiles(SourcePath.kt:106)
	at org.javacs.kt.KotlinTextDocumentService.doLint(KotlinTextDocumentService.kt:196)
	at org.javacs.kt.KotlinTextDocumentService.access$doLint(KotlinTextDocumentService.kt:26)
	at org.javacs.kt.KotlinTextDocumentService$lintLater$1.invoke(KotlinTextDocumentService.kt:185)
	at org.javacs.kt.KotlinTextDocumentService$lintLater$1.invoke(KotlinTextDocumentService.kt:26)
	at org.javacs.kt.util.DebouncerKt$sam$java_lang_Runnable$0.run(Debouncer.kt)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at org.jetbrains.kotlin.cli.jvm.compiler.CliModuleAnnotationsResolver.getAnnotationsOnContainingModule(CliModuleAnnotationsResolver.kt:37)
	at org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker$Companion.loadExperimentalities(ExperimentalUsageChecker.kt:112)
	at org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker$Companion.loadExperimentalities(ExperimentalUsageChecker.kt:109)
	at org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker$Companion.access$loadExperimentalities(ExperimentalUsageChecker.kt:62)
	at org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker.check(ExperimentalUsageChecker.kt:58)
	at org.jetbrains.kotlin.resolve.calls.CallCompleter.completeCall(CallCompleter.kt:94)
	at org.jetbrains.kotlin.resolve.calls.CallCompleter.completeCallForArgument(CallCompleter.kt:352)
	at org.jetbrains.kotlin.resolve.calls.CallCompleter.completeOneArgument(CallCompleter.kt:310)
	at org.jetbrains.kotlin.resolve.calls.CallCompleter.completeArguments(CallCompleter.kt:294)
	at org.jetbrains.kotlin.resolve.calls.CallCompleter.completeResolvedCallAndArguments(CallCompleter.kt:147)
	at org.jetbrains.kotlin.resolve.calls.CallCompleter.completeCall(CallCompleter.kt:79)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.doResolveCallOrGetCachedResults(CallResolver.java:607)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.lambda$resolveCallWithKnownCandidate$4(CallResolver.java:558)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:91)
	at org.jetbrains.kotlin.resolve.calls.CallResolver.resolveCallWithKnownCandidate(CallResolver.java:548)
	at org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.resolveSpecialConstructionAsCall(ControlStructureTypingUtils.java:124)
	at org.jetbrains.kotlin.types.expressions.ControlStructureTypingVisitor.visitIfExpression(ControlStructureTypingVisitor.java:124)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitIfExpression(ExpressionTypingVisitorForStatements.java:406)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitIfExpression(ExpressionTypingVisitorForStatements.java:62)
	at org.jetbrains.kotlin.psi.KtIfExpression.accept(KtIfExpression.java:33)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:172)
	... 74 more

Guava dependency resolution bug

There is an issue with the Guava dependency.

When including Guava explicitly as dependency...

  • The tests will pass
  • The language server will complain at runtime that the LSP4J/Xtext Guava dependency is missing and fail when trying to provide code completion

When omitting an explicit Guava listing...

  • The tests will fail throwing NoSuchMethodExceptions
  • The language server will work

Currently the Guava dependency is omitted, so the application will work but many of the tests do not work currently. This should obviously be resolved somehow.

Global collection initializer functions shown as "unresolved reference"

When working with a Gradle project previously created in Intellij IDEA, the global functions mapOf, listOf, emptyMap, and similar all display as unresolved references. I'm not sure if this is a project configuration issue caused by moving from Intellij to VSCode, or if it's a bug, as I don't have any other types of projects available to test with.

image

Android Projects error on R.java

Android compiles all of it's layout files into a R.java file that is compiled into the resulting apk file. The way we resolve this on other projects (such as vim-javacomoplete2) is to include the .class files from the build folders into the classpath that it uses.

This doesn't seem to work here. I've not delved into why yet - I'm assuming that this language server doesn't allow for classes on the classpath but it also could just be that Android Kotlin toolchain streamlines this somehow and doesn't output the same thing.

Opening this as a placeholder until I figure it out :)

Find Sources of Compiled Symbol

When I try to go to a compiled symbol, I get exactly the same error as #23.

I used a common class (java.util.ArrayList) and the file path shown in the error message does exist on my system so the general setup is correct but the feature for loading the file is not working (it also works out of the box with vscode-java).

Example:

package test

import java.util.ArrayList

Put cursor on "ArrayList" and hit F12.

Actual result: The result is an error as described above.

Expected result: The Java sources for the class are shown.

Version is the most current in the extension marketplace: 0.1.8.

using the kotlin lsp server with emacs eglot

Hello, I'm trying to use kotlin lsp with the emacs eglot lsp impllementation, but I'm having some problems.

Is it supposed to work to use the stdio mode, or is there a port to connect to? Is there some basic sanity checks I can do by hand to see that the kotlin lsp responds correctly?

VSCode Extension on MacOSX - Not working with JDK 10

After resolving my previous issue the next error message I got was The Kotlin Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

This was resolved by changing JAVA_HOME to point to JDK 8 and not 10.

If anyone does hit this, it seems you can also change the VSCode config value java.home to point to the JDK version to use.

Logging here for 2 reasons:

  1. if someone else has this issue maybe they can find this to resolve their issues
  2. happy to try and help out with maybe declaring dependencies or something to make this more robust? not really sure where that would be - a rough pointer and I will gladly dig into it.

I worked this out by trying to run the language server manually and got this at the command prompt.

Exception in thread "main" java.lang.IllegalStateException: LOGGING: Loading modules: [java.se, javafx.base, javafx.controls, javafx.fxml, javafx.graphics, javafx.media, javafx.swing, javafx.web, jdk.accessibility, jdk.attach, jdk.compiler, jdk.dynalink, jdk.httpserver, jdk.incubator.httpclient, jdk.jartool, jdk.javadoc, jdk.jconsole, jdk.jdi, jdk.jfr, jdk.jshell, jdk.jsobject, jdk.management, jdk.management.cmm, jdk.management.jfr, jdk.management.resource, jdk.net, jdk.packager, jdk.packager.services, jdk.scripting.nashorn, jdk.sctp, jdk.security.auth, jdk.security.jgss, jdk.unsupported, jdk.xml.dom, oracle.desktop, oracle.net, java.base, java.compiler, java.datatransfer, java.desktop, java.xml, java.instrument, java.logging, java.management, java.management.rmi, java.rmi, java.naming, java.prefs, java.scripting, java.security.jgss, java.security.sasl, java.sql, java.sql.rowset, java.xml.crypto, jdk.internal.jvmstat, jdk.management.agent, jdk.jdwp.agent, jdk.internal.ed, jdk.internal.le, jdk.internal.opt, jdk.jlink] (no MessageCollector configured)
	at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.report(ClasspathRootsResolver.kt:314)
	at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.report$default(ClasspathRootsResolver.kt:312)
	at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.addModularRoots(ClasspathRootsResolver.kt:254)
	at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.computeRoots(ClasspathRootsResolver.kt:124)
	at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.convertClasspathRoots(ClasspathRootsResolver.kt:79)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:233)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:117)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:413)
	at org.javacs.kt.Compiler.<init>(Compiler.kt:52)
	at org.javacs.kt.CompilerClassPath.<init>(CompilerClassPath.kt:9)
	at org.javacs.kt.KotlinLanguageServer.<init>(KotlinLanguageServer.kt:14)
	at org.javacs.kt.MainKt.main(Main.kt:8)

Deal with workspaces containing workspaces

Currently, #1 (Multiple declarations bug) will still affect projects that are structured like this:

root
├───bin << This (empty) folder is actually ignored instead of the other bin folder
├───build.gradle
└───subdir
    ├───bin << These (compiler-generated) copies of the source files should be ignored
    │   └───main
    │       └───kotlin
    │           └───App.kt << Issues "Conflicting overload error"
    ├───build.gradle
    └───src
        └───main
            └───kotlin
                └───App.kt << Issues "Conflicting overload error"

Implement Rename

Implement "rename"-refactoring for symbols. This will require the language server to scan files for references and modify symbols/imports (if needed).

No suggestion options for enum types if companion object exists on enum class

public enum class TokenType(val type: String) {
    ILLEGAL("ILLEGAL"),
    EOF("EOF"),
    /* ... */
    RBRACE("{");

    companion object {
        private val tokens: HashMap<String, TokenType> = HashMap()

        init {
            for(token in TokenType.values()) {
                tokens.put(token.type, token)
            }
        }

        public fun get(type: String): TokenType = this.tokens.getOrDefault(type, TokenType.ILLEGAL)
    }
}

With this code, if i type TokenType., i get the following options:
image

If i comment out the companion object, i get the full list of enum types:
image

Go to definition in decompiled files silently crashes server

System: macOS 10.13.5

When attempting to open a definition that is located in a *.class file, the server crashes silently and is unable to handle any requests, even though the file was successfully decompiled.

Log just before the crash:

[INFO]      async       main    Found declaration descriptor public open fun <U : (kotlin.Any..kotlin.Any?)> supplyAsync(p0: (java.util.function.Supplier<(U..U?)>..java.util.function.Supplier<(U..U?)>?), p1: (java.util.concurrent.Executor..java.util.concurrent.Executor?)): (java.util.concurrent.CompletableFuture<(U..U?)>..java.util.concurrent.CompletableFuture<(U..U?)>?) defined in java.util.concurrent.CompletableFuture[JavaMethodDescriptor@2e1b3fcd]
[INFO]      async       main    Decompiling CompletableFuture8154208674483070079.class using Fernflower...
[INFO]      async       main    Finished decompiling CompletableFuture8154208674483070079.class
[INFO]      async       main    Finished in 1947 ms

After the crash, dozens of warnings from LSP4J appear:

[WARNING]   client      org.ec  Unmatched cancel notification for request id 145
                        lipse.
                        lsp4j.
                        jsonrp
                        c.Remo
                        teEndp
                        oint  

Package name completion

Automatically suggest the correct package name with code completion when creating a new Kotlin file.

No error if 'fun` keyword missing in abstract function in enums

public enum class TokenType(val type: String) {
    ILLEGAL("ILLEGAL"),
	/* ... */
    RBRACE("{");

    abstract parse(): Statement
}

This silently fails, no error on abstract parse(): Statement even though the fun keyword is missing. There is no error on the enum types either about a missing implementation. Only if the funkeyword is added, do they error correctly

VSCode Extension on MacOSX - Couldn't start client Kotlin Language Server

So on MacOSX, the extension just does not run when installed from the store. I get a notification with Couldn't start client Kotlin Language Server

The cause is that the kotlin-language-server is not marked as executable, so doing the following chmod +x ~/.vscode/extensions/fwcd.kotlin-0.1.3/build/install/kotlin-language-server/bin/kotlin-language-server helped resolve this particular issue.

Not sure how, but if you can give me a pointer, happy to do a PR to add this into the build maybe?

In the developer tools console this is the stack trace

INFO no standard startup: not just one text editor
extensionService.ts:870 [xabikos.JavaScriptSnippets]: Unknown language in `contributes.JavaScriptSnippets.language`. Provided value: vue
w._logMessageInConsole @ extensionService.ts:870
console.ts:136 [Extension Host] Activating Kotlin language server...
console.ts:136 [Extension Host] Looking for java in PATH
console.ts:136 [Extension Host] /Users/rmaclean/.vscode/extensions/fwcd.kotlin-0.1.3/build/install/kotlin-language-server/bin/kotlin-language-server 
notificationsAlerts.ts:42 Couldn't start client Kotlin Language Server
e.onDidNotificationChange @ notificationsAlerts.ts:42
console.ts:136 [Extension Host] rejected promise not handled within 1 second
t.log @ console.ts:136
mainThreadExtensionService.ts:43 [fwcd.kotlin]spawn EACCES
e.$onExtensionRuntimeError @ mainThreadExtensionService.ts:43
mainThreadExtensionService.ts:44 Error: spawn EACCES
	at exports._errnoException (util.js:1050:11)
	at ChildProcess.spawn (internal/child_process.js:319:11)
	at Object.exports.spawn (child_process.js:390:9)
	at _getServerWorkingDir.then.serverWorkingDir (/Users/rmaclean/.vscode/extensions/fwcd.kotlin-0.1.3/node_modules/vscode-languageclient/lib/main.js:346:40)
	at <anonymous>
e.$onExtensionRuntimeError @ mainThreadExtensionService.ts:44

Question: Eclipse Che?

Has this language server been used/tested with Eclipse Che at all? I see the issue for supporting Eclipse itself, but no mention of Che.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.