diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt index 464112b069e..7c00c4d14d3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -156,7 +156,8 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour val attachments = arrayOf(attachmentByPsiFile(sourcePosition.file), attachmentByPsiFile(codeFragment), - Attachment("breakpoint.info", "line: ${sourcePosition.line}")) + Attachment("breakpoint.info", "line: ${sourcePosition.line}"), + Attachment("context.info", codeFragment.context?.text ?: "null")) LOG.error(LogMessageEx.createEvent( "Couldn't evaluate expression", ExceptionUtil.getThrowableText(e), diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt index 41df37164ed..d2cca24673f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -17,11 +17,14 @@ package org.jetbrains.kotlin.idea.debugger.evaluate import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil +import com.intellij.diagnostic.LogMessageEx +import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager import com.intellij.psi.impl.PsiModificationTrackerImpl +import com.intellij.util.ExceptionUtil import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult @@ -32,6 +35,8 @@ import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.* import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.ErrorMessage import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.Status import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.idea.util.attachment.attachmentByPsiFile +import org.jetbrains.kotlin.idea.util.attachment.mergeAttachments import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode @@ -49,13 +54,16 @@ fun getFunctionForExtractedFragment( fun getErrorMessageForExtractFunctionResult(analysisResult: AnalysisResult, tmpFile: KtFile): String { if (KotlinInternalMode.enabled) { - LOG.error("Couldn't extract function for debugger:\n" + - "FILE NAME: ${breakpointFile.name}\n" + - "BREAKPOINT LINE: $breakpointLine\n" + - "CODE FRAGMENT:\n${codeFragment.text}\n" + - "ERRORS:\n${analysisResult.messages.map { "$it: ${it.renderMessage()}" }.joinToString("\n")}\n" + - "TMPFILE_TEXT:\n${tmpFile.text}\n" + - "FILE TEXT: \n${breakpointFile.text}\n") + val attachments = arrayOf(attachmentByPsiFile(tmpFile), + attachmentByPsiFile(breakpointFile), + attachmentByPsiFile(codeFragment), + Attachment("breakpoint.info", "line: $breakpointLine"), + Attachment("context.info", codeFragment.context?.text ?: "null"), + Attachment("errors.info", analysisResult.messages.map { "$it: ${it.renderMessage()}" }.joinToString("\n"))) + LOG.error(LogMessageEx.createEvent( + "Internal error during evaluate expression", + ExceptionUtil.getThrowableText(Throwable("Extract function fails with ${analysisResult.messages.joinToString { it.name }}")), + mergeAttachments(*attachments))) } return analysisResult.messages.map { errorMessage -> val message = when(errorMessage) { diff --git a/idea/src/org/jetbrains/kotlin/idea/util/attachment/attachmentUtils.kt b/idea/src/org/jetbrains/kotlin/idea/util/attachment/attachmentUtils.kt index 951970540c9..3b3cbd197a2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/attachment/attachmentUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/attachment/attachmentUtils.kt @@ -16,9 +16,9 @@ package org.jetbrains.kotlin.idea.util.attachment -import com.intellij.psi.PsiFile -import com.intellij.openapi.diagnostic.Attachment import com.intellij.diagnostic.AttachmentFactory +import com.intellij.openapi.diagnostic.Attachment +import com.intellij.psi.PsiFile fun attachmentByPsiFileAsArray(file: PsiFile?): Array { val attachment = attachmentByPsiFile(file) @@ -48,9 +48,9 @@ fun mergeAttachments(vararg attachments: Attachment?): Attachment { val builder = StringBuilder() attachments.forEach { if (it != null) { - builder.append("\n----- START ${it.path} -----\n") + builder.append("----- START ${it.path} -----\n") builder.append(it.displayText) - builder.append("\n----- END ${it.path} -----\n") + builder.append("\n----- END ${it.path} -----\n\n") } }