Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #600

Open
stefanpartheym opened this issue Oct 31, 2024 · 5 comments

Comments

@stefanpartheym
Copy link

stefanpartheym commented Oct 31, 2024

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

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
<File name: dummy.virtual.kt, Physical: true>
<ELEMENT>class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
        return "Test output: ${input}"
    }
}</ELEMENT>
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
<File name: dummy.virtual.kt, Physical: true>
<ELEMENT>class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
        return "Test output: ${input}"
    }
}</ELEMENT>
	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:

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.

@stefanpartheym
Copy link
Author

Ok, so I'm using the following workaround now to suppress these annoying notifications I get in neovim when the LSP throws an exception:

  {
    "folke/noice.nvim",
    event = "VeryLazy",
    opts = {
      routes = {
        {
          -- Disable annoying error from `kotlin_language_server`.
          opts = { skip = true },
          filter = {
            event = "notify",
            find = "^kotlin_language_server: %-32603: Internal error%.$",
          },
        },
      },
    },
  },

This can be helpful for other people with the same issue/setup too.

Feel free to close this issue, if the exception is too hard to track down and fix. I understand it is tedious to debug something like this with very little documentation on the kotlin compiler internals.

@AlexandrosAlexiou
Copy link
Contributor

AlexandrosAlexiou commented Nov 11, 2024

This is fixed in this fork.
This repository is not maintained.

@stefanpartheym
Copy link
Author

stefanpartheym commented Nov 12, 2024

Thank you @AlexandrosAlexiou !
I tried it out by cloning the fork locally and setting it up in nvim-lspconfig. Works great! The annoying internal errors are gone now.

For anyone interested in how to setup the forked repo:

Clone and build the fork:

git clone https://github.com/kotlin-community-tools/kotlin-language-server.git
cd kotlin-language-server
./gradlew :server:installDist

nvim config:

      require("lspconfig").kotlin_language_server.setup({
        cmd = {
          os.getenv("HOME") .. "/.lsp/kotlin-language-server/server/build/install/server/bin/kotlin-language-server",
        },
        capabilities = capabilities,
      })

@fwcd fwcd reopened this Jan 18, 2025
@fwcd
Copy link
Owner

fwcd commented Jan 18, 2025

Appreciate the efforts on maintaining an active fork, but please keep the issue open if it's not fixed here yet (and use downstream issues otherwise).

@fwcd
Copy link
Owner

fwcd commented Jan 18, 2025

I've cherry-picked kotlin-community-tools/kotlin-language-server@eadceb7 to #612, though this doesn't fix the issue and just prevents it from potentially crashing the language server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants