Propagate reports from script dependency resolver
Compiler: show as compiler messages IDE: annotate code in a separate highlighting pass
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
val <error descr="Can't use">java</error> = "j"
|
||||
val <warning descr="Shouldn't use">scala</warning> = "s"
|
||||
|
||||
val result = <error descr="Can't use">java</error> + <warning descr="Shouldn't use">scala</warning>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package custom.scriptDefinition
|
||||
|
||||
import kotlin.script.dependencies.*
|
||||
import kotlin.script.templates.*
|
||||
import java.io.File
|
||||
|
||||
class TestDependenciesResolver : DependenciesResolver {
|
||||
override fun resolve(scriptContents: ScriptContents, environment: Environment): DependenciesResolver.ResolveResult {
|
||||
val reports = ArrayList<ScriptReport>()
|
||||
scriptContents.text?.let { text ->
|
||||
text.lines().forEachIndexed { lineIndex, line ->
|
||||
val adjustedLine = line.replace(Regex("(<error descr=\"Can't use\">)|(</error>)|(<warning descr=\"Shouldn't use\">)|(</warning>)"), "")
|
||||
Regex("java").findAll(adjustedLine).forEach {
|
||||
reports.add(
|
||||
ScriptReport(
|
||||
"Can't use",
|
||||
ScriptReport.Severity.ERROR,
|
||||
ScriptReport.Position(lineIndex, it.range.first, lineIndex, it.range.last + 1)
|
||||
)
|
||||
)
|
||||
}
|
||||
Regex("scala").findAll(adjustedLine).forEach {
|
||||
reports.add(
|
||||
ScriptReport(
|
||||
"Shouldn't use",
|
||||
ScriptReport.Severity.WARNING,
|
||||
ScriptReport.Position(lineIndex, it.range.first, lineIndex, it.range.last + 1)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DependenciesResolver.ResolveResult.Success(
|
||||
ScriptDependencies(
|
||||
classpath = listOf(environment["template-classes"] as File)
|
||||
),
|
||||
reports
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ScriptTemplateDefinition(TestDependenciesResolver::class, scriptFilePattern = "script.kts")
|
||||
class Template : Base()
|
||||
|
||||
open class Base {
|
||||
val i = 3
|
||||
val str = ""
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
val <error descr="Can't use">java = "j"</error>
|
||||
val <warning descr="Shouldn't use">scala = "s"</warning>
|
||||
|
||||
val result = <error descr="Can't use">java +</error>
|
||||
<warning descr="Shouldn't use">scala</warning>
|
||||
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
package custom.scriptDefinition
|
||||
|
||||
import kotlin.script.dependencies.*
|
||||
import kotlin.script.templates.*
|
||||
import java.io.File
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
|
||||
class TestDependenciesResolver : ScriptDependenciesResolver {
|
||||
override fun resolve(
|
||||
script: ScriptContents,
|
||||
environment: Map<String, Any?>?,
|
||||
report: (ScriptDependenciesResolver.ReportSeverity, String, ScriptContents.Position?) -> Unit, previousDependencies: KotlinScriptExternalDependencies?
|
||||
): Future<KotlinScriptExternalDependencies?> {
|
||||
script.text?.let { text ->
|
||||
text.lines().forEachIndexed { lineIndex, line ->
|
||||
val adjustedLine = line.replace(Regex("(<error descr=\"Can't use\">)|(</error>)|(<warning descr=\"Shouldn't use\">)|(</warning>)"), "")
|
||||
Regex("java").findAll(adjustedLine).forEach {
|
||||
val columnIndex = it.range.first
|
||||
report(ScriptDependenciesResolver.ReportSeverity.ERROR, "Can't use", ScriptContents.Position(lineIndex, columnIndex))
|
||||
}
|
||||
Regex("scala").findAll(adjustedLine).forEach {
|
||||
val columnIndex = it.range.first
|
||||
report(ScriptDependenciesResolver.ReportSeverity.WARNING, "Shouldn't use", ScriptContents.Position(lineIndex, columnIndex))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CompletableFuture.completedFuture(
|
||||
object : KotlinScriptExternalDependencies {
|
||||
override val classpath: Iterable<File> = listOf(environment?.get("template-classes") as File)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ScriptTemplateDefinition(TestDependenciesResolver::class, scriptFilePattern = "script.kts")
|
||||
class Template : Base()
|
||||
|
||||
open class Base {
|
||||
val i = 3
|
||||
val str = ""
|
||||
}
|
||||
Reference in New Issue
Block a user