Scripts: Check if file is in all script dependencies class files scope instead of searching for module info
^KT-32799 Fixed ^KT-16760 Add test
This commit is contained in:
+10
-11
@@ -21,23 +21,22 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.ResolveScopeProvider
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.idea.caches.project.ScriptDependenciesInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.ScriptDependenciesSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.getModuleInfoByVirtualFile
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||
|
||||
class ScriptDependenciesResolveScopeProvider : ResolveScopeProvider() {
|
||||
override fun getResolveScope(file: VirtualFile, project: Project): GlobalSearchScope? {
|
||||
if (ScriptConfigurationManager.getInstance(project).getAllScriptsDependenciesClassFiles().isEmpty()) return null
|
||||
val manager = ScriptConfigurationManager.getInstance(project)
|
||||
if (manager.getAllScriptsDependenciesClassFiles().isEmpty()) return null
|
||||
|
||||
if (file !in manager.getAllScriptsDependenciesClassFilesScope() && file !in manager.getAllScriptDependenciesSourcesScope()) {
|
||||
return null
|
||||
}
|
||||
|
||||
val moduleInfo = getModuleInfoByVirtualFile(project, file) ?: return null
|
||||
val scriptDependenciesModuleInfo = (moduleInfo as? ScriptDependenciesInfo)
|
||||
?: (moduleInfo as? ScriptDependenciesSourceInfo)?.binariesModuleInfo
|
||||
?: return null
|
||||
return GlobalSearchScope.union(
|
||||
arrayOf(
|
||||
GlobalSearchScope.fileScope(project, file),
|
||||
*scriptDependenciesModuleInfo.dependencies().map { it.contentScope() }.toTypedArray()
|
||||
)
|
||||
arrayOf(
|
||||
GlobalSearchScope.fileScope(project, file),
|
||||
*ScriptDependenciesInfo.ForProject(project).dependencies().map { it.contentScope() }.toTypedArray()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package test;
|
||||
|
||||
public class Task {
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
test.JavaClass().task() {
|
||||
it.outputs
|
||||
}
|
||||
|
||||
// CONFLICTING_MODULE
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
package custom.scriptDefinition
|
||||
|
||||
import java.io.File
|
||||
import kotlin.script.dependencies.*
|
||||
import kotlin.script.experimental.dependencies.*
|
||||
import kotlin.script.templates.ScriptTemplateDefinition
|
||||
import kotlin.script.experimental.location.*
|
||||
|
||||
class TestDependenciesResolver : DependenciesResolver {
|
||||
override fun resolve(
|
||||
scriptContents: ScriptContents,
|
||||
environment: Environment
|
||||
): DependenciesResolver.ResolveResult {
|
||||
return DependenciesResolver.ResolveResult.Success(
|
||||
ScriptDependencies(
|
||||
classpath = listOf(environment["template-classes"] as File)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ScriptExpectedLocations([ScriptExpectedLocation.Everywhere])
|
||||
@ScriptTemplateDefinition(TestDependenciesResolver::class, scriptFilePattern = "script.kts")
|
||||
open class Template
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
package test;
|
||||
|
||||
public interface Action<T> {
|
||||
void execute(T t);
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package test;
|
||||
|
||||
public class JavaClass {
|
||||
public Task task(Action<? super Task> configureAction) {
|
||||
return new Task();
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package test;
|
||||
|
||||
public class Task {
|
||||
public String getOutputs() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -100,19 +100,7 @@ abstract class AbstractScriptConfigurationTest : KotlinCompletionTestCase() {
|
||||
ModuleRootModificationUtil.addDependency(myModule, newModule)
|
||||
}
|
||||
|
||||
if (configureConflictingModule in environment) {
|
||||
val sharedLib = VfsUtil.findFileByIoFile(environment["lib-classes"] as File, true)!!
|
||||
if (module == null) {
|
||||
myModule = createTestModuleByName("mainModule")
|
||||
}
|
||||
module.addDependency(projectLibrary("sharedLib", classesRoot = sharedLib))
|
||||
}
|
||||
|
||||
if (module != null) {
|
||||
ModuleRootModificationUtil.updateModel(module) { model ->
|
||||
model.sdk = sdk
|
||||
}
|
||||
|
||||
module.addDependency(
|
||||
projectLibrary(
|
||||
"script-runtime",
|
||||
@@ -130,6 +118,21 @@ abstract class AbstractScriptConfigurationTest : KotlinCompletionTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
if (configureConflictingModule in environment) {
|
||||
val sharedLib = VfsUtil.findFileByIoFile(environment["lib-classes"] as File, true)!!
|
||||
if (module == null) {
|
||||
// Force create module if it doesn't exist
|
||||
myModule = createTestModuleByName("mainModule")
|
||||
}
|
||||
module.addDependency(projectLibrary("sharedLib", classesRoot = sharedLib))
|
||||
}
|
||||
|
||||
if (module != null) {
|
||||
ModuleRootModificationUtil.updateModel(module) { model ->
|
||||
model.sdk = sdk
|
||||
}
|
||||
}
|
||||
|
||||
createFileAndSyncDependencies(mainScriptFile)
|
||||
}
|
||||
|
||||
|
||||
Generated
+5
@@ -71,6 +71,11 @@ public class ScriptConfigurationHighlightingTestGenerated extends AbstractScript
|
||||
runTest("idea/testData/script/definition/highlighting/customLibrary/");
|
||||
}
|
||||
|
||||
@TestMetadata("customLibraryInModuleDeps")
|
||||
public void testCustomLibraryInModuleDeps() throws Exception {
|
||||
runTest("idea/testData/script/definition/highlighting/customLibraryInModuleDeps/");
|
||||
}
|
||||
|
||||
@TestMetadata("doNotSpeakAboutJava")
|
||||
public void testDoNotSpeakAboutJava() throws Exception {
|
||||
runTest("idea/testData/script/definition/highlighting/doNotSpeakAboutJava/");
|
||||
|
||||
Reference in New Issue
Block a user