fwcd / kotlin-language-server Goto Github PK
View Code? Open in Web Editor NEWKotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
License: MIT License
Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
License: MIT License
Implement "rename"-refactoring for symbols. This will require the language server to scan files for references and modify symbols/imports (if needed).
When typing
values.map({ it * 2 }).
code completion is provided successfully (due to the closing parenthesis), but when writing
values.map { it * 2 }.
it fails.
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!
I've noticed that often some variables dont give autocomplete options.
This is usually resolved by hovering over the variable for the lang server to resolve its type, after which it then will give autocomplete options
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?
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 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.
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 ')'
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.
Automatically update imports and package declarations when moving a Kotlin source file.
This should be possible soon using a new API in VSCode: microsoft/vscode#43768
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.
There is an issue with the Guava dependency.
When including Guava explicitly as dependency...
When omitting an explicit Guava listing...
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.
Perform logging using the window/logMessage
method instead of writing to stdout.
interface LogMessageParams {
/**
* The message type. See {@link MessageType}
*/
type: number;
/**
* The actual message
*/
message: string;
}
See https://microsoft.github.io/language-server-protocol/specification#window_logMessage
Implement a Java to Kotlin converter as in the Kotlin Web Demo:
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
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:
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)
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.
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"
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?
Similar to the Java language server that uses the Eclipse JDT underneath, this language server might be able to use the officially supported Kotlin plugin for Eclipse by JetBrains instead of the internal Kotlin compiler API.
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.
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:
If i comment out the companion object, i get the full list of enum types:
We can't reformat our code. Maybe we can use ktlint
There is no document formatter for 'kotlin'-files installed.
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.
Support vscode-java, so Java can see Kotlin classes and vice versa.
Investigate support for incremental compilation using the official Kotlin compiler API instead of the mechanism currently used (as described in the README), because this might improve performance considerably.
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.
Automatically suggest the correct package name with code completion when creating a new Kotlin file.
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!")
}
{}
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?
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 :)
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.
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.
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 fun
keyword is added, do they error correctly
Create a command to automatically import/unimport symbols.
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
Find symbols across compiled classes (amongst the dependencies), for example when jumping to the definition of an external symbol.
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.
The field
keyword should be highlighted the same as if
, while
, etc.
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)
Reproduce:
BufferedReader(reader)
val buf = BufferedReader(reader)
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.
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
Currently the Kotlin-DSL classes (in *.gradle.kts buildscripts) are not resolved by the Language Server, which results in a lot of errors.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.