diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/ScriptExternalHighlightingPass.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/ScriptExternalHighlightingPass.kt index 5d0d454f671..b1313dd8751 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/ScriptExternalHighlightingPass.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/ScriptExternalHighlightingPass.kt @@ -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? { - 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 { 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 } } diff --git a/idea/testData/script/definition/highlighting/errorResolver/script.kts b/idea/testData/script/definition/highlighting/errorResolver/script.kts new file mode 100644 index 00000000000..a137642f282 --- /dev/null +++ b/idea/testData/script/definition/highlighting/errorResolver/script.kts @@ -0,0 +1,6 @@ + +val s = 3 +val g = 4 + +// CHECK_WARNINGS +// CHECK_INFOS \ No newline at end of file diff --git a/idea/testData/script/definition/highlighting/errorResolver/template/template.kt b/idea/testData/script/definition/highlighting/errorResolver/template/template.kt new file mode 100644 index 00000000000..d85668a9c6d --- /dev/null +++ b/idea/testData/script/definition/highlighting/errorResolver/template/template.kt @@ -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 \ No newline at end of file diff --git a/idea/testData/script/definition/highlighting/throwingResolver/script.kts b/idea/testData/script/definition/highlighting/throwingResolver/script.kts index 3b227722bec..4b09b3b0a64 100644 --- a/idea/testData/script/definition/highlighting/throwingResolver/script.kts +++ b/idea/testData/script/definition/highlighting/throwingResolver/script.kts @@ -1,5 +1,4 @@ - + Exception from resolver"> val s = 3 val g = 4 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt index 6faa2e701ce..1f43ab24545 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt @@ -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")) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/script/ScriptConfigurationHighlightingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/script/ScriptConfigurationHighlightingTestGenerated.java index 3566e49660f..2021ff7f1df 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/script/ScriptConfigurationHighlightingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/script/ScriptConfigurationHighlightingTestGenerated.java @@ -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/");