import { DebugProtocol } from 'vscode-debugprotocol' ; import { ChromeDebugSession } from '../chrome/chromeDebugSession' ; import { IDebugTransformer , ISetBreakpointsResponseBody , IStackTraceResponseBody , IScopesResponseBody } from '../debugAdapterInterfaces' ; /**
 * Converts from 1 based lines/cols on the client side to 0 based lines/cols on the target side
 */ export class LineColTransformer implements IDebugTransformer { columnBreakpointsEnabled : boolean ; constructor ( private _session ) { } public setBreakpoints ( args ) { args . breakpoints . forEach ( bp => this . convertClientLocationToDebugger ( bp ) ) ; if ( ! this . columnBreakpointsEnabled ) { args . breakpoints . forEach ( bp => bp . column = undefined ) ; } return args ; } public setBreakpointsResponse ( response ) { response . breakpoints . forEach ( bp => this . convertDebuggerLocationToClient ( bp ) ) ; if ( ! this . columnBreakpointsEnabled ) { response . breakpoints . forEach ( bp => bp . column = 1 ) ; } } public stackTraceResponse ( response ) { response . stackFrames . forEach ( frame => this . convertDebuggerLocationToClient ( frame ) ) ; } public breakpointResolved ( bp ) { this . convertDebuggerLocationToClient ( bp ) ; if ( ! this . columnBreakpointsEnabled ) { bp . column = undefined ; } } public scopeResponse ( scopeResponse ) { scopeResponse . scopes . forEach ( scope => this . mapScopeLocations ( scope ) ) ; } public mappedExceptionStack ( location ) { this . convertDebuggerLocationToClient ( location ) ; } private mapScopeLocations ( scope ) { this . convertDebuggerLocationToClient ( scope ) ; if ( typeof scope . endLine === 'number' ) { const endScope = { line : scope . endLine , column : scope . endColumn } ; this . convertDebuggerLocationToClient ( endScope ) ; scope . endLine = endScope . line ; scope . endColumn = endScope . column ; } } public convertClientLocationToDebugger ( location ) { if ( typeof location . line === 'number' ) { location . line = this . convertClientLineToDebugger ( location . line ) ; } if ( typeof location . column === 'number' ) { location . column = this . convertClientColumnToDebugger ( location . column ) ; } } public convertDebuggerLocationToClient ( location ) { if ( typeof location . line === 'number' ) { location . line = this . convertDebuggerLineToClient ( location . line ) ; } if ( typeof location . column === 'number' ) { location . column = this . convertDebuggerColumnToClient ( location . column ) ; } } public convertClientLineToDebugger ( line ) { return ( < any > this . _session ) . convertClientLineToDebugger ( line ) ; } public convertDebuggerLineToClient ( line ) { return ( < any > this . _session ) . convertDebuggerLineToClient ( line ) ; } public convertClientColumnToDebugger ( column ) { return ( < any > this . _session ) . convertClientColumnToDebugger ( column ) ; } public convertDebuggerColumnToClient ( column ) { return ( < any > this . _session ) . convertDebuggerColumnToClient ( column ) ; } }