fwcd / fwcd/kotlin-language-server

Exception in LSP when hovering the beginning or ending curly braces of a `class`, `data class` or `enum`: `java.lang.UnsupportedOperationException: Should not be called`

Open
#600 5 comments 2 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm using `kotlin-language-server` with neovim and https://github.com/neovim/nvim-lspconfig.

Unfortunately, I always receive this annoying notification from the LSP in neovim, whenever I hover the beginning or ending curly braces of a `class`, `data class` or `enum`:
`kotlin_language_server: -32603: Internal error.`
![image](https://github.com/user-attachments/assets/6c3d481e-62a5-4735-a90f-dac2d5e58cbe)

I checked the logs, and this exception thrown in the LSP seems to be the source of this notification:
```
ERROR: Exception while analyzing expression in (1,50) in /dummy.virtual.kt

Attachments:
causeThrowable
java.lang.UnsupportedOperationException: Should not be called
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)

----
expression.kt

class TestClass(val testValue: String) {

fun testFunction(input: String): String {
return "Test output: ${input}"
}
}
org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: Exception while analyzing expression in (1,50) in /dummy.virtual.kt
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:253)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:225)
at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.UnsupportedOperationException: Should not be called
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
... 18 more
Okt. 31, 2024 11:38:11 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SCHWERWIEGEND: Internal error: org.javacs.kt.util.KotlinLSException: Error while analyzing: class TestClass(val testValue: String) {

fun testFunction(input: String): String {
...
}
java.util.concurrent.CompletionException: org.javacs.kt.util.KotlinLSException: Error while analyzing: class TestClass(val testValue: String) {

fun testFunction(input: String): String {
...
}
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: org.javacs.kt.util.KotlinLSException: Error while analyzing: class TestClass(val testValue: String) {

fun testFunction(input: String): String {
...
}
at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:574)
at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
... 3 more
Caused by: org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression in (1,50) in /dummy.virtual.kt

Attachments:
causeThrowable
java.lang.UnsupportedOperationException: Should not be called
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)

----
expression.kt

class TestClass(val testValue: String) {

fun testFunction(input: String): String {
return "Test output: ${input}"
}
}
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:261)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:225)
at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
... 12 more
Caused by: java.lang.UnsupportedOperationException: Should not be called
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
... 18 more
```

Minimal sample code to reproduce:
```kotlin
package org.example

import java.time.LocalDate

class TestClass(val testValue: String) { // LSP throws an exception, when this curly brace is hovered with cursor

fun testFunction(input: String): String {
return "Test output: ${input}"
}
} // LSP throws an exception, when this curly brace is hovered with cursor

fun main() {
val test = TestClass("test")
println(test.testFunction("Hello World!"))
}
```

Is there a way to work around this?
Thanks

I know, this is a duplicate of #599, but I think mine is more detailed.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce document highlighting at the opening and closing braces in the reported class, data class, and enum examples. Start with DocumentHighlight.kt and follow the calls through CompiledFile.kt, Compiler.kt, and KotlinTextDocumentService.kt; done means those positions no longer produce an internal LSP error.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.