From 761b7a99d7907a3e285ecb9aec6cc875336a104c Mon Sep 17 00:00:00 2001 From: "Victoria.Petrakovich" Date: Mon, 22 Dec 2025 18:25:45 +0000 Subject: [PATCH] [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 GitOrigin-RevId: 8ff45c5876fefaa6607759dd8791296ac85dd95d --- ...etupEnvironmentNotificationProviderTest.kt | 37 +++++++++++++++++++ ...linSetupEnvironmentNotificationProvider.kt | 6 ++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProviderTest.kt diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProviderTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProviderTest.kt new file mode 100644 index 000000000000..67560c3b2301 --- /dev/null +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProviderTest.kt @@ -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)) + } +} \ No newline at end of file diff --git a/plugins/kotlin/project-configuration/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt b/plugins/kotlin/project-configuration/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt index 7874efc3acf0..ed29a7dc1e14 100644 --- a/plugins/kotlin/project-configuration/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt +++ b/plugins/kotlin/project-configuration/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt @@ -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