[kotlin] K2: add .main.kts tests

#KTIJ-33875

GitOrigin-RevId: b6afbd8e876f643161220af7d556f5488843d779
This commit is contained in:
Vlad Koshkin
2025-04-23 23:13:56 +00:00
committed by intellij-monorepo-bot
parent 6455ee5c72
commit 97fc17037e
7 changed files with 27 additions and 23 deletions
@@ -48,9 +48,7 @@ class MainKtsScriptConfigurationProvider(val project: Project, val coroutineScop
override suspend fun create(virtualFile: VirtualFile, definition: ScriptDefinition): ScriptConfigurationWithSdk? {
val ktFile = readAction { virtualFile.toPsiFile(project) as? KtFile } ?: return null
val hasNoDependencies = readAction { ktFile.hasNoDependencies() }
if (hasNoDependencies) {
createNoDependenciesConfiguration(virtualFile)
} else if (ktFile.dependenciesExistLocally()) {
if (hasNoDependencies || ktFile.dependenciesExistLocally()) {
refineConfiguration(virtualFile)
}
@@ -2,7 +2,6 @@
package org.jetbrains.kotlin.idea.k2.highlighting
import com.intellij.codeInsight.daemon.impl.EditorTracker
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.psi.PsiFile
import com.intellij.testFramework.GlobalState
@@ -20,9 +19,7 @@ import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
import org.jetbrains.kotlin.psi.KtFile
abstract class AbstractK2ScriptHighlightingTest : AbstractHighlightingMetaInfoTest() {
override fun doMultiFileTest(
files: List<PsiFile>, globalDirectives: Directives
) {
override fun doMultiFileTest(files: List<PsiFile>, globalDirectives: Directives) {
runBlocking {
DefaultScriptResolutionStrategy.getInstance(project).execute(*(files.mapNotNull { it as? KtFile }.toTypedArray())).join()
}
@@ -30,10 +27,6 @@ abstract class AbstractK2ScriptHighlightingTest : AbstractHighlightingMetaInfoTe
super.doMultiFileTest(files, globalDirectives)
}
override fun getProject(): Project {
return super.getProject()
}
override fun runInDispatchThread(): Boolean = false
override fun setUp() {
@@ -34,4 +34,9 @@ public class K2MainKtsHighlightingTestGenerated extends AbstractK2MainKtsHighlig
public void testDefinitionDependencies() throws Exception {
runTest("../../idea/tests/testData/mainKts/definitionDependencies.main.kts");
}
@TestMetadata("fileName.main.kts")
public void testFileName() throws Exception {
runTest("../../idea/tests/testData/mainKts/fileName.main.kts");
}
}
@@ -1,10 +1,6 @@
// CHECK_SYMBOL_NAMES
// HIGHLIGHTER_ATTRIBUTES_KEY
import kotlin.reflect.KClass
listOf(DependsOn::class, Repository::class, Import::class, CompilerOptions::class, ScriptFileLocation::class)
fun mainKtsDefaultImports(): List<KClass<out Annotation>> {
return listOf(DependsOn::class, Repository::class, Import::class, CompilerOptions::class, ScriptFileLocation::class)
}
println(mainKtsDefaultImports())
println("Hello from ${__FILE__.path}")
@@ -1,10 +1,6 @@
// CHECK_SYMBOL_NAMES
// HIGHLIGHTER_ATTRIBUTES_KEY
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_KEYWORD'")!>import<!> kotlin.reflect.<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_TRAIT'")!>KClass<!>
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>listOf<!>(<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>DependsOn<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>Repository<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>Import<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>CompilerOptions<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>ScriptFileLocation<!>::class)
fun <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_FUNCTION_DECLARATION'")!>mainKtsDefaultImports<!>(): <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_TRAIT'")!>List<!><<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_TRAIT'")!>KClass<!><<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_BUILTIN_ANNOTATION'")!>out<!> <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_TRAIT'")!>Annotation<!>>> {
return <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>listOf<!>(<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>DependsOn<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>Repository<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>Import<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>CompilerOptions<!>::class, <!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>ScriptFileLocation<!>::class)
}
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>println<!>(<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>mainKtsDefaultImports<!>())
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>println<!>("Hello from ${<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_LOCAL_VARIABLE'")!>__FILE__<!>.<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_SYNTHETIC_EXTENSION_PROPERTY'")!>path<!>}")
@@ -0,0 +1,8 @@
// CHECK_SYMBOL_NAMES
// HIGHLIGHTER_ATTRIBUTES_KEY
// ALLOW_ERRORS
@file:ScriptFileLocation("MY_CUSTOM_LOCATION")
println("Hello from ${MY_CUSTOM_LOCATION.path}")
println("I'm not $__FILE__") //error
@@ -0,0 +1,8 @@
// CHECK_SYMBOL_NAMES
// HIGHLIGHTER_ATTRIBUTES_KEY
// ALLOW_ERRORS
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_ANNOTATION'")!>@<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_KEYWORD'")!>file<!>:ScriptFileLocation<!>("MY_CUSTOM_LOCATION")
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>println<!>("Hello from ${<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_LOCAL_VARIABLE'")!>MY_CUSTOM_LOCATION<!>.<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_SYNTHETIC_EXTENSION_PROPERTY'")!>path<!>}")
<!HIGHLIGHTING("severity='SYMBOL_TYPE_SEVERITY'; highlightingTextAttributesKey='KOTLIN_PACKAGE_FUNCTION_CALL'")!>println<!>("I'm not $<!HIGHLIGHTING("severity='ERROR'; descr='[UNRESOLVED_REFERENCE] Unresolved reference '__FILE__'.'; highlightingTextAttributesKey='WRONG_REFERENCES_ATTRIBUTES'")!>__FILE__<!>") //error