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

References to external dependencies can't be found on top-level statements #497

Open
RenanKummer opened this issue Sep 20, 2023 · 6 comments

Comments

@RenanKummer
Copy link

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.

@RenanKummer
Copy link
Author

RenanKummer commented Sep 20, 2023

Given that Spring Boot heavily depends on top-level annotations to work, this is a damaging bug.

@saluzafa
Copy link

saluzafa commented Oct 5, 2023

Hello there!

Getting the same problem here, I can confirm this is a damaging bug 😕.

Is there any temporary fix? @fwcd

@RenanKummer
Copy link
Author

Hi all,

Just following up on this. Any chances a fix could be included in the roadmap?

@saluzafa
Copy link

saluzafa commented Feb 8, 2024

Bump @fwcd

@fwcd
Copy link
Owner

fwcd commented Feb 8, 2024

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.

@saluzafa
Copy link

saluzafa commented Feb 9, 2024

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.

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