Provide line info for scratch output in scratch toolwindow
^KT-24016
This commit is contained in:
+1
-1
@@ -40,7 +40,7 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||
createInlay(file, expression.lineStart, inlayText, output.type)
|
||||
|
||||
if (output.type == ScratchOutputType.ERROR) {
|
||||
error(file, output.text)
|
||||
ToolWindowScratchOutputHandler.handle(file, expression, output)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.scratch.output
|
||||
|
||||
import com.intellij.execution.filters.OpenFileHyperlinkInfo
|
||||
import com.intellij.execution.impl.ConsoleViewImpl
|
||||
import com.intellij.execution.ui.ConsoleViewContentType
|
||||
import com.intellij.ide.scratch.ScratchFileType
|
||||
@@ -28,6 +29,7 @@ import com.intellij.openapi.wm.ToolWindow
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor
|
||||
import com.intellij.openapi.wm.ToolWindowFactory
|
||||
import com.intellij.openapi.wm.ToolWindowManager
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.idea.scratch.ScratchExpression
|
||||
import org.jetbrains.kotlin.idea.scratch.ScratchFile
|
||||
@@ -37,10 +39,22 @@ object ToolWindowScratchOutputHandler : ScratchOutputHandlerAdapter() {
|
||||
|
||||
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
return testPrint(file, output.text)
|
||||
return testPrint(file, output.text, expression)
|
||||
}
|
||||
|
||||
printToConsole(file.project) {
|
||||
val psiFile = file.getPsiFile()
|
||||
if (psiFile != null) {
|
||||
printHyperlink(
|
||||
getLineInfo(psiFile, expression),
|
||||
OpenFileHyperlinkInfo(
|
||||
project,
|
||||
psiFile.virtualFile,
|
||||
expression.lineStart
|
||||
)
|
||||
)
|
||||
print(" ", ConsoleViewContentType.NORMAL_OUTPUT)
|
||||
}
|
||||
print(output.text, output.type.convert())
|
||||
}
|
||||
}
|
||||
@@ -88,6 +102,9 @@ object ToolWindowScratchOutputHandler : ScratchOutputHandlerAdapter() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLineInfo(psiFile: PsiFile, expression: ScratchExpression) =
|
||||
"${psiFile.name}:${expression.lineStart + 1}"
|
||||
|
||||
private fun ScratchOutputType.convert() = when (this) {
|
||||
ScratchOutputType.OUTPUT -> ConsoleViewContentType.SYSTEM_OUTPUT
|
||||
ScratchOutputType.RESULT -> ConsoleViewContentType.NORMAL_OUTPUT
|
||||
@@ -108,12 +125,14 @@ object ToolWindowScratchOutputHandler : ScratchOutputHandlerAdapter() {
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
private fun testPrint(file: ScratchFile, output: String) {
|
||||
private fun testPrint(file: ScratchFile, output: String, expression: ScratchExpression? = null) {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
WriteCommandAction.runWriteCommandAction(file.project) {
|
||||
val psiFile = file.getPsiFile()!!
|
||||
psiFile.addAfter(
|
||||
KtPsiFactory(file.project).createComment("/** $output */"),
|
||||
KtPsiFactory(file.project).createComment(
|
||||
"/** ${expression?.let { getLineInfo(psiFile, expression) + " " } ?: ""}$output */"
|
||||
),
|
||||
psiFile.lastChild
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
foo() // ERROR: Unresolved reference: foo
|
||||
/** Unresolved reference: foo */
|
||||
/** unresolved.kts:1 Unresolved reference: foo */
|
||||
/** Compilation Error */
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
foo() // ERROR: error: unresolved reference: foo
|
||||
/** error: unresolved reference: foo
|
||||
foo() // ERROR: error: unresolved reference: foo
|
||||
/** unresolved.kts:1 error: unresolved reference: foo
|
||||
|
||||
foo()
|
||||
|
||||
|
||||
+3
-3
@@ -5,9 +5,9 @@ foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among
|
||||
fun goo(a: String) { // ERROR: Unresolved reference: goo
|
||||
super.goo(a)
|
||||
}
|
||||
/** Unresolved reference: foo */
|
||||
/** Cannot choose among the following candidates without completing type inference:
|
||||
/** unresolvedMultiline.kts:1 Unresolved reference: foo */
|
||||
/** unresolvedMultiline.kts:1 Cannot choose among the following candidates without completing type inference:
|
||||
@HidesMembers public inline fun <T> Iterable<???>.forEach(action: (???) -> Unit): Unit defined in kotlin.collections
|
||||
@HidesMembers public inline fun <K, V> Map<out ???, ???>.forEach(action: (Map.Entry<???, ???>) -> Unit): Unit defined in kotlin.collections */
|
||||
/** Unresolved reference: goo */
|
||||
/** unresolvedMultiline.kts:5 Unresolved reference: goo */
|
||||
/** Compilation Error */
|
||||
+2
-2
@@ -5,7 +5,7 @@ foo.forEach { // ERROR: error: unr
|
||||
fun goo(a: String) { // ERROR: error: unresolved reference: goo
|
||||
super.goo(a)
|
||||
}
|
||||
/** error: unresolved reference: foo
|
||||
/** unresolvedMultiline.kts:1 error: unresolved reference: foo
|
||||
|
||||
foo.forEach {
|
||||
|
||||
@@ -18,7 +18,7 @@ error: cannot choose among the following candidates without completing type infe
|
||||
foo.forEach {
|
||||
|
||||
^ */
|
||||
/** error: unresolved reference: goo
|
||||
/** unresolvedMultiline.kts:5 error: unresolved reference: goo
|
||||
|
||||
super.goo(a)
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
val a = "a".repeat(100) // RESULT: val a: String
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
/** aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
/** veryLongOutput.kts:2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
val a = "a".repeat(100)
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
/** aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
/** veryLongOutput.kts:2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
Reference in New Issue
Block a user