From c9583f3aa92f51cb025fca91194a891a29e4b388 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 16 Jun 2016 20:02:38 +0300 Subject: [PATCH] Provide (not actually correct) resolve scope for script files that have dependencies This is needed for completion to determine dependencies of the file correctly --- .../KotlinScriptResolveScopeProvider.kt | 38 +++++++++++++++++++ idea/src/META-INF/plugin.xml | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt new file mode 100644 index 00000000000..8ae5f19f42c --- /dev/null +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.core.script.dependencies + +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.ResolveScopeProvider +import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager +import org.jetbrains.kotlin.script.KotlinConfigurableScriptDefinition +import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromTemplate +import org.jetbrains.kotlin.script.getScriptDefinition + +class KotlinScriptResolveScopeProvider : ResolveScopeProvider() { + override fun getResolveScope(file: VirtualFile, project: Project): GlobalSearchScope? { + val scriptDefinition = getScriptDefinition(file, project) ?: return null + // TODO: this should get this particular scripts dependencies + if (scriptDefinition is KotlinConfigurableScriptDefinition || scriptDefinition is KotlinScriptDefinitionFromTemplate) { + // TODO: should include the file itself + return KotlinScriptConfigurationManager.getInstance(project).getAllScriptsClasspathScope() + } + return null + } +} \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 679b33d4c8e..fe8f98bf5a9 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -1600,8 +1600,8 @@ - +