kotlin-language-server
kotlin-language-server copied to clipboard
References to external dependencies can't be found on top-level statements
Auto-import is not working for top-level statements referring to external dependencies.
@RestController
class HelloController {
@GetMapping("/hello")
fun getHello(): Map<String,String> {
return mapOf(Pair("message","Hello world!"));
}
}
In the code above, auto-import works for @GetMapping (inside the class), but it doesn't work for @RestController (top-level). The following exception is thrown by kotlin-language-server:
expression.kt
@RestController
public class HelloController {
@GetMapping("/hello")
fun getHello(): Map<String,String> {
return mapOf(Pair("message", "Hello world!"));
}
}
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:543)
... 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:120)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:170)
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:71)
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
In fact, simply moving the cursor through keyboard or mouse click to any place outside the class declaration already triggers this exception.
Given that Spring Boot heavily depends on top-level annotations to work, this is a damaging bug.
Hello there!
Getting the same problem here, I can confirm this is a damaging bug 😕.
Is there any temporary fix? @fwcd
Hi all,
Just following up on this. Any chances a fix could be included in the roadmap?
Bump @fwcd
Please keep discussions focused on the actual topic and refrain from "bumps" and pings. This is a volunteer-driven project and someone will have to put in the time and effort to chase down these issues. PRs are always very much appreciated.
Please keep discussions focused on the actual topic and refrain from "bumps" and pings. This is a volunteer-driven project and someone will have to put in the time and effort to chase down these issues. PRs are always very much appreciated.
I'm sorry, didn't meant to be rude. Have a nice day.