import * as vscode from "vscode" ; import Reporter from "./telemetry" ; import { UserError , FrameSummary } from "arepl-backend" ; import Utilities , { DefaultDict } from "./utilities" ; /**
 * shows error icons
 */ export default class PythonInlinePreview { public printResults : string [ ] ; public errorDecorationType : vscode . TextEditorDecorationType ; constructor ( private reporter , context ) { this . errorDecorationType = vscode . window . createTextEditorDecorationType ( { gutterIconPath : context . asAbsolutePath ( 'media/red.jpg' ) , } ) ; } /**
     * Safe - catches and logs any exceptions
     */ public showInlineErrors ( error , userErrorMsg ) { try { if ( userErrorMsg . includes ( "AREPL has ran into an error" ) ) { } const decorations = this . convertErrorToDecorationOptions ( error ) ; if ( vscode . window . activeTextEditor ) { vscode . window . activeTextEditor . setDecorations ( this . errorDecorationType , decorations [ "<string>" ] ) ; } } catch ( internalError ) { if ( internalError instanceof Error ) { this . reporter . sendError ( internalError ) ; } else { this . reporter . sendError ( new Error ( internalError ) ) ; } } } private showInternalError ( internalError ) { throw Error ( 'not implemented' ) ; } private convertFrameToDecorationOption ( frame ) { const lineNum = frame . lineno - 1 ; const endCharNum = 0 ; const range = new vscode . Range ( lineNum , 0 , lineNum , endCharNum ) ; const text = "" ; return { range , renderOptions : { after : { contentText : text } } } ; } /**
     * converts error to dictionary of error decorations indexed by filename
     */ private convertErrorToDecorationOptions ( error ) { const decorations = new DefaultDict ( Array ) ; if ( Utilities . isEmpty ( error ) ) return { '<string>' : [ ] } ; const flattenedErrors = Utilities . flattenNestedObjectWithMultipleKeys ( error , [ "__context__" , "__cause__" ] ) ; flattenedErrors . forEach ( error => { error . stack [ "py/seq" ] . forEach ( frame => { decorations [ frame . filename ] . push ( this . convertFrameToDecorationOption ( frame ) ) ; } ) ; } ) ; return decorations ; } }