Scratch: substring output and print it to separate tool window if it is too long
^KT-24016 In Progress
This commit is contained in:
+7
-1
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.impl.FontInfo
|
||||
import com.intellij.openapi.editor.markup.TextAttributes
|
||||
import com.intellij.openapi.fileEditor.TextEditor
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.ui.Colors
|
||||
import com.intellij.ui.JBColor
|
||||
import com.intellij.util.ui.UIUtil
|
||||
@@ -44,7 +45,12 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||
}
|
||||
|
||||
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
||||
createInlay(file, expression.lineStart, output.text.substringBefore("\n"), output.type)
|
||||
val inlayText = StringUtil.shortenTextWithEllipsis(output.text.substringBefore("\n"), 50, 0)
|
||||
if (inlayText != output.text) {
|
||||
ScratchToolWindow.addMessageToToolWindow(file.project, output.text, ConsoleViewContentType.NORMAL_OUTPUT)
|
||||
}
|
||||
|
||||
createInlay(file, expression.lineStart, inlayText, output.type)
|
||||
|
||||
if (output.type == ScratchOutputType.ERROR) {
|
||||
error(file, output.text)
|
||||
|
||||
+7
-1
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.impl.FontInfo
|
||||
import com.intellij.openapi.editor.markup.TextAttributes
|
||||
import com.intellij.openapi.fileEditor.TextEditor
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.ui.Colors
|
||||
import com.intellij.ui.JBColor
|
||||
import com.intellij.util.ui.UIUtil
|
||||
@@ -44,7 +45,12 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||
}
|
||||
|
||||
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
||||
createInlay(file, expression.lineStart, output.text.substringBefore("\n"), output.type)
|
||||
val inlayText = StringUtil.shortenTextWithEllipsis(output.text.substringBefore("\n"), 50, 0)
|
||||
if (inlayText != output.text) {
|
||||
ScratchToolWindow.addMessageToToolWindow(file.project, output.text, ConsoleViewContentType.NORMAL_OUTPUT)
|
||||
}
|
||||
|
||||
createInlay(file, expression.lineStart, inlayText, output.type)
|
||||
|
||||
if (output.type == ScratchOutputType.ERROR) {
|
||||
error(file, output.text)
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.intellij.openapi.wm.ToolWindowManager
|
||||
|
||||
class ScratchToolWindowFactory : ToolWindowFactory {
|
||||
companion object {
|
||||
val ID = "Scratch error output"
|
||||
val ID = "Scratch Output"
|
||||
}
|
||||
|
||||
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among the following candidates without completing type inference:
|
||||
foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among the following candidates wi...
|
||||
1 + 1
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
val a = "a".repeat(100) // RESULT: val a: String
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
val a = "a".repeat(100)
|
||||
a
|
||||
@@ -0,0 +1,2 @@
|
||||
val a = "a".repeat(100)
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
+10
@@ -81,6 +81,11 @@ public class ScratchRunActionTestGenerated extends AbstractScratchRunActionTest
|
||||
runTest("idea/testData/scratch/var.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("veryLongOutput.kts")
|
||||
public void testVeryLongOutput() throws Exception {
|
||||
runTest("idea/testData/scratch/veryLongOutput.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("when.kts")
|
||||
public void testWhen() throws Exception {
|
||||
runTest("idea/testData/scratch/when.kts");
|
||||
@@ -149,6 +154,11 @@ public class ScratchRunActionTestGenerated extends AbstractScratchRunActionTest
|
||||
runTest("idea/testData/scratch/var.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("veryLongOutput.kts")
|
||||
public void testVeryLongOutput() throws Exception {
|
||||
runTest("idea/testData/scratch/veryLongOutput.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("when.kts")
|
||||
public void testWhen() throws Exception {
|
||||
runTest("idea/testData/scratch/when.kts");
|
||||
|
||||
Reference in New Issue
Block a user