Propagate reports from script dependency resolver

Compiler: show as compiler messages
IDE: annotate code in a separate highlighting pass
This commit is contained in:
Pavel V. Talanov
2017-06-19 19:58:51 +03:00
parent 96c2a589c0
commit 10e14103b6
16 changed files with 393 additions and 20 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.script
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
@@ -27,7 +28,7 @@ import kotlin.reflect.KClass
import kotlin.script.dependencies.ScriptContents
import kotlin.script.dependencies.ScriptDependencies
abstract class KotlinScriptExternalImportsProviderBase(private val project: Project): KotlinScriptExternalImportsProvider {
abstract class KotlinScriptExternalImportsProviderBase(private val project: Project) : KotlinScriptExternalImportsProvider {
fun getScriptContents(scriptDefinition: KotlinScriptDefinition, file: VirtualFile)
= BasicScriptContents(file, getAnnotations = { loadAnnotations(scriptDefinition, file) })
@@ -61,10 +62,12 @@ abstract class KotlinScriptExternalImportsProviderBase(private val project: Proj
file: VirtualFile
): ScriptDependencies? {
val scriptContents = getScriptContents(scriptDef, file)
return scriptDef.dependencyResolver.resolve(
val result = scriptDef.dependencyResolver.resolve(
scriptContents,
(scriptDef as? KotlinScriptDefinitionFromAnnotatedTemplate)?.environment ?: emptyMap()
).dependencies
)
ServiceManager.getService(project, ScriptReportSink::class.java)?.attachReports(file, result.reports)
return result.dependencies
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2017 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.script
import com.intellij.openapi.vfs.VirtualFile
import kotlin.script.dependencies.ScriptReport
interface ScriptReportSink {
fun attachReports(scriptFile: VirtualFile, reports: List<ScriptReport>)
}