Scripts: switch ScriptReportSink to new scripting API
Use ScriptDiagnostic instead of ScripReport
This commit is contained in:
+15
-14
@@ -38,7 +38,8 @@ import com.intellij.psi.PsiFile
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.idea.core.script.IdeScriptReportSink
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
import kotlin.script.experimental.api.ScriptDiagnostic
|
||||
import kotlin.script.experimental.api.SourceCode
|
||||
|
||||
class ScriptExternalHighlightingPass(
|
||||
private val file: KtFile,
|
||||
@@ -53,8 +54,8 @@ class ScriptExternalHighlightingPass(
|
||||
|
||||
val reports = IdeScriptReportSink.getReports(file.virtualFile)
|
||||
|
||||
val annotations = reports.mapNotNull { (message, severity, position) ->
|
||||
val (startOffset, endOffset) = position?.let { computeOffsets(document, position) } ?: 0 to 0
|
||||
val annotations = reports.mapNotNull { (message, severity, _ , location) ->
|
||||
val (startOffset, endOffset) = location?.let { computeOffsets(document, it) } ?: 0 to 0
|
||||
val annotation = Annotation(
|
||||
startOffset,
|
||||
endOffset,
|
||||
@@ -73,14 +74,14 @@ class ScriptExternalHighlightingPass(
|
||||
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument!!, 0, file.textLength, infos, colorsScheme, id)
|
||||
}
|
||||
|
||||
private fun computeOffsets(document: Document, position: ScriptReport.Position): Pair<Int, Int> {
|
||||
val startLine = position.startLine.coerceLineIn(document)
|
||||
val startOffset = document.offsetBy(startLine, position.startColumn)
|
||||
private fun computeOffsets(document: Document, position: SourceCode.Location): Pair<Int, Int> {
|
||||
val startLine = position.start.line.coerceLineIn(document)
|
||||
val startOffset = document.offsetBy(startLine, position.start.col)
|
||||
|
||||
val endLine = position.endLine?.coerceAtLeast(startLine)?.coerceLineIn(document) ?: startLine
|
||||
val endLine = position.end?.line?.coerceAtLeast(startLine)?.coerceLineIn(document) ?: startLine
|
||||
val endOffset = document.offsetBy(
|
||||
endLine,
|
||||
position.endColumn ?: document.getLineEndOffset(endLine)
|
||||
position.end?.col ?: document.getLineEndOffset(endLine)
|
||||
).coerceAtLeast(startOffset)
|
||||
|
||||
return startOffset to endOffset
|
||||
@@ -92,13 +93,13 @@ class ScriptExternalHighlightingPass(
|
||||
return (getLineStartOffset(line) + col).coerceIn(getLineStartOffset(line), getLineEndOffset(line))
|
||||
}
|
||||
|
||||
private fun ScriptReport.Severity.convertSeverity(): HighlightSeverity? {
|
||||
private fun ScriptDiagnostic.Severity.convertSeverity(): HighlightSeverity? {
|
||||
return when (this) {
|
||||
ScriptReport.Severity.FATAL -> ERROR
|
||||
ScriptReport.Severity.ERROR -> ERROR
|
||||
ScriptReport.Severity.WARNING -> WARNING
|
||||
ScriptReport.Severity.INFO -> INFORMATION
|
||||
ScriptReport.Severity.DEBUG -> if (ApplicationManager.getApplication().isInternal) INFORMATION else null
|
||||
ScriptDiagnostic.Severity.FATAL -> ERROR
|
||||
ScriptDiagnostic.Severity.ERROR -> ERROR
|
||||
ScriptDiagnostic.Severity.WARNING -> WARNING
|
||||
ScriptDiagnostic.Severity.INFO -> INFORMATION
|
||||
ScriptDiagnostic.Severity.DEBUG -> if (ApplicationManager.getApplication().isInternal) INFORMATION else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-14
@@ -41,7 +41,8 @@ import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptsCompilationConfigurationUpdater
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
import kotlin.script.experimental.api.ScriptDiagnostic
|
||||
import kotlin.script.experimental.api.SourceCode
|
||||
|
||||
class ScriptExternalHighlightingPass(
|
||||
private val file: KtFile,
|
||||
@@ -74,8 +75,8 @@ class ScriptExternalHighlightingPass(
|
||||
|
||||
val reports = IdeScriptReportSink.getReports(file.virtualFile)
|
||||
|
||||
val annotations = reports.mapNotNull { (message, severity, position) ->
|
||||
val (startOffset, endOffset) = position?.let { computeOffsets(document, position) } ?: 0 to 0
|
||||
val annotations = reports.mapNotNull { (message, severity, _ , location) ->
|
||||
val (startOffset, endOffset) = location?.let { computeOffsets(document, it) } ?: 0 to 0
|
||||
val annotation = Annotation(
|
||||
startOffset,
|
||||
endOffset,
|
||||
@@ -94,14 +95,14 @@ class ScriptExternalHighlightingPass(
|
||||
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument!!, 0, file.textLength, infos, colorsScheme, id)
|
||||
}
|
||||
|
||||
private fun computeOffsets(document: Document, position: ScriptReport.Position): Pair<Int, Int> {
|
||||
val startLine = position.startLine.coerceLineIn(document)
|
||||
val startOffset = document.offsetBy(startLine, position.startColumn)
|
||||
private fun computeOffsets(document: Document, position: SourceCode.Location): Pair<Int, Int> {
|
||||
val startLine = position.start.line.coerceLineIn(document)
|
||||
val startOffset = document.offsetBy(startLine, position.start.col)
|
||||
|
||||
val endLine = position.endLine?.coerceAtLeast(startLine)?.coerceLineIn(document) ?: startLine
|
||||
val endLine = position.end?.line?.coerceAtLeast(startLine)?.coerceLineIn(document) ?: startLine
|
||||
val endOffset = document.offsetBy(
|
||||
endLine,
|
||||
position.endColumn ?: document.getLineEndOffset(endLine)
|
||||
position.end?.col ?: document.getLineEndOffset(endLine)
|
||||
).coerceAtLeast(startOffset)
|
||||
|
||||
return startOffset to endOffset
|
||||
@@ -113,13 +114,13 @@ class ScriptExternalHighlightingPass(
|
||||
return (getLineStartOffset(line) + col).coerceIn(getLineStartOffset(line), getLineEndOffset(line))
|
||||
}
|
||||
|
||||
private fun ScriptReport.Severity.convertSeverity(): HighlightSeverity? {
|
||||
private fun ScriptDiagnostic.Severity.convertSeverity(): HighlightSeverity? {
|
||||
return when (this) {
|
||||
ScriptReport.Severity.FATAL -> ERROR
|
||||
ScriptReport.Severity.ERROR -> ERROR
|
||||
ScriptReport.Severity.WARNING -> WARNING
|
||||
ScriptReport.Severity.INFO -> INFORMATION
|
||||
ScriptReport.Severity.DEBUG -> if (ApplicationManager.getApplication().isInternal) INFORMATION else null
|
||||
ScriptDiagnostic.Severity.FATAL -> ERROR
|
||||
ScriptDiagnostic.Severity.ERROR -> ERROR
|
||||
ScriptDiagnostic.Severity.WARNING -> WARNING
|
||||
ScriptDiagnostic.Severity.INFO -> INFORMATION
|
||||
ScriptDiagnostic.Severity.DEBUG -> if (ApplicationManager.getApplication().isInternal) INFORMATION else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user