Scripts: display errors from external resolver in panel if text range is empty
This commit is contained in:
+10
-11
@@ -32,6 +32,7 @@ import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.project.DumbAware
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
|
||||
import org.jetbrains.kotlin.idea.core.script.IdeScriptReportSink
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
@@ -48,27 +49,26 @@ class ScriptExternalHighlightingPass(
|
||||
val reports = file.virtualFile.getUserData(IdeScriptReportSink.Reports) ?: return
|
||||
|
||||
val annotations = reports.mapNotNull { (message, severity, position) ->
|
||||
val (startOffset, endOffset) = computeOffsets(document, position) ?: return@mapNotNull null
|
||||
Annotation(
|
||||
val (startOffset, endOffset) = position?.let { computeOffsets(document, position) } ?: 0 to 0
|
||||
val annotation = Annotation(
|
||||
startOffset,
|
||||
endOffset,
|
||||
severity.convertSeverity() ?: return@mapNotNull null,
|
||||
message,
|
||||
message
|
||||
)
|
||||
|
||||
// if range is empty, show notification panel in editor
|
||||
annotation.isFileLevelAnnotation = startOffset == endOffset
|
||||
|
||||
annotation
|
||||
}
|
||||
|
||||
val infos = annotations.map { HighlightInfo.fromAnnotation(it) }
|
||||
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument!!, 0, file.textLength, infos, colorsScheme, id)
|
||||
}
|
||||
|
||||
private fun computeOffsets(document: Document, position: ScriptReport.Position?): Pair<Int, Int>? {
|
||||
if (position == null) {
|
||||
// TODO: better presentation of those errors
|
||||
// if no position was specified, mark first two lines as an error
|
||||
return computeOffsets(document, ScriptReport.Position(0, 0, 1))
|
||||
}
|
||||
|
||||
private fun computeOffsets(document: Document, position: ScriptReport.Position): Pair<Int, Int> {
|
||||
val startLine = position.startLine.coerceLineIn(document)
|
||||
val startOffset = document.offsetBy(startLine, position.startColumn)
|
||||
|
||||
@@ -78,7 +78,6 @@ class ScriptExternalHighlightingPass(
|
||||
position.endColumn ?: document.getLineEndOffset(endLine)
|
||||
).coerceAtLeast(startOffset)
|
||||
|
||||
// TODO: presentation when range is empty?
|
||||
return startOffset to endOffset
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ class ScriptExternalHighlightingPass(
|
||||
ScriptReport.Severity.ERROR -> ERROR
|
||||
ScriptReport.Severity.WARNING -> WARNING
|
||||
ScriptReport.Severity.INFO -> INFORMATION
|
||||
else -> null
|
||||
ScriptReport.Severity.DEBUG -> if (KotlinInternalMode.enabled) INFORMATION else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<info descr="Info"></info><warning descr="Warning"></warning><error descr="Error"></error>
|
||||
val s = 3
|
||||
val g = 4
|
||||
|
||||
// CHECK_WARNINGS
|
||||
// CHECK_INFOS
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package custom.scriptDefinition
|
||||
|
||||
import java.io.File
|
||||
import kotlin.script.dependencies.*
|
||||
import kotlin.script.experimental.dependencies.*
|
||||
import kotlin.script.templates.ScriptTemplateDefinition
|
||||
|
||||
class TestDependenciesResolver : DependenciesResolver {
|
||||
override fun resolve(
|
||||
scriptContents: ScriptContents,
|
||||
environment: Environment
|
||||
): DependenciesResolver.ResolveResult {
|
||||
return DependenciesResolver.ResolveResult.Failure(
|
||||
ScriptReport("Error"),
|
||||
ScriptReport("Info", ScriptReport.Severity.INFO),
|
||||
ScriptReport("Warning", ScriptReport.Severity.WARNING),
|
||||
ScriptReport("Debug", ScriptReport.Severity.DEBUG)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ScriptTemplateDefinition(TestDependenciesResolver::class, scriptFilePattern = "script.kts")
|
||||
open class Template
|
||||
@@ -1,5 +1,4 @@
|
||||
<error descr="TestDependenciesResolver threw exception IllegalStateException:
|
||||
Exception from resolver">
|
||||
</error>
|
||||
Exception from resolver"></error>
|
||||
val s = 3
|
||||
val g = 4
|
||||
@@ -44,7 +44,10 @@ import kotlin.script.dependencies.Environment
|
||||
abstract class AbstractScriptConfigurationHighlightingTest : AbstractScriptConfigurationTest() {
|
||||
fun doTest(path: String) {
|
||||
configureScriptFile(path)
|
||||
checkHighlighting(editor, false, false)
|
||||
checkHighlighting(
|
||||
editor,
|
||||
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_WARNINGS"),
|
||||
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_INFOS"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
+6
@@ -79,6 +79,12 @@ public class ScriptConfigurationHighlightingTestGenerated extends AbstractScript
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("errorResolver")
|
||||
public void testErrorResolver() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/script/definition/highlighting/errorResolver/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaNestedClass")
|
||||
public void testJavaNestedClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/script/definition/highlighting/javaNestedClass/");
|
||||
|
||||
Reference in New Issue
Block a user