[kotlin] KTIJ-36032 Show Kotlin not configured notification in source roots not registered as source roots

Merge-request: IJ-MR-183600
Merged-by: Victoria Petrakovich <Victoria.Petrakovich@jetbrains.com>

GitOrigin-RevId: 8ff45c5876fefaa6607759dd8791296ac85dd95d
This commit is contained in:
Victoria.Petrakovich
2025-12-22 18:25:45 +00:00
committed by intellij-monorepo-bot
parent f4d1cc8f2d
commit 761b7a99d7
2 changed files with 42 additions and 1 deletions
@@ -0,0 +1,37 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import org.junit.Test
import org.junit.internal.runners.JUnit38ClassRunner
import org.junit.runner.RunWith
@RunWith(JUnit38ClassRunner::class)
class KotlinSetupEnvironmentNotificationProviderTest : LightJavaCodeInsightFixtureTestCase() {
@Test
fun testSrcMainKotlin() {
val kotlinFileRelativePath = "/src/main/kotlin/TestKotlin.kt"
createKotlinFile(kotlinFileRelativePath)
assertFileIsUnderSourceRoots(kotlinFileRelativePath, fileShouldBeUnderSourceRoots = true)
}
@Test
fun testSrcMainKotlin_smth() {
val kotlinFileRelativePath = "/src/main/kotlin_smth.kt"
createKotlinFile(kotlinFileRelativePath)
assertFileIsUnderSourceRoots(kotlinFileRelativePath, fileShouldBeUnderSourceRoots = false)
}
private fun createKotlinFile(kotlinFileRelativePath: String) {
val kotlinFile = myFixture.addFileToProject(kotlinFileRelativePath, "")
myFixture.openFileInEditor(kotlinFile.virtualFile)
}
private fun assertFileIsUnderSourceRoots(kotlinFileRelativePath: String, fileShouldBeUnderSourceRoots: Boolean) {
val selectedEditor = FileEditorManager.getInstance(project).selectedEditor
val selectedFile = selectedEditor?.file ?: error("file $kotlinFileRelativePath has to be in the editor")
assertEquals(fileShouldBeUnderSourceRoots, KotlinSetupEnvironmentNotificationProvider().fileIsUnderKotlinSourceRoot(selectedFile))
}
}
@@ -76,7 +76,7 @@ class KotlinSetupEnvironmentNotificationProvider : EditorNotificationProvider {
return null
}
if (!ModuleRootManager.getInstance(module).fileIndex.isInSourceContent(file)) {
if (!ModuleRootManager.getInstance(module).fileIndex.isInSourceContent(file) && !fileIsUnderKotlinSourceRoot(file)) {
return null
}
@@ -98,6 +98,10 @@ class KotlinSetupEnvironmentNotificationProvider : EditorNotificationProvider {
return null
}
fun fileIsUnderKotlinSourceRoot(file: VirtualFile): Boolean {
return file.path.contains("src/main/kotlin/") || file.path.contains("src/test/kotlin/")
}
// We do this check only for JPS projects because for other build systems this problem is not topical
private fun kotlinStdlibExistsOnDiskForJPS(module: Module, project: Project): Boolean {
val moduleDependencies = module.findModuleEntity()?.dependencies ?: return false