-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathlineNumberTransformer.ts
50 lines (39 loc) · 1.84 KB
/
lineNumberTransformer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import {DebugProtocol} from 'vscode-debugprotocol';
import {IDebugTransformer, ISetBreakpointsResponseBody, IStackTraceResponseBody} from '../WebKitAdapterInterfaces';
/**
* Converts from 1 based lines on the client side to 0 based lines on the target side
*/
export class LineNumberTransformer implements IDebugTransformer {
private _targetLinesStartAt1: boolean;
private _clientLinesStartAt1: boolean;
constructor(targetLinesStartAt1: boolean) {
this._targetLinesStartAt1 = targetLinesStartAt1;
}
public initialize(args: DebugProtocol.InitializeRequestArguments): void {
this._clientLinesStartAt1 = args.linesStartAt1;
}
public setBreakpoints(args: DebugProtocol.SetBreakpointsArguments): void {
args.lines = args.lines.map(line => this.convertClientLineToTarget(line));
}
public setBreakpointsResponse(response: ISetBreakpointsResponseBody): void {
response.breakpoints.forEach(bp => bp.line = this.convertTargetLineToClient(bp.line));
}
public stackTraceResponse(response: IStackTraceResponseBody): void {
response.stackFrames.forEach(frame => frame.line = this.convertTargetLineToClient(frame.line));
}
private convertClientLineToTarget(line: number): number {
if (this._targetLinesStartAt1) {
return this._clientLinesStartAt1 ? line : line + 1;
}
return this._clientLinesStartAt1 ? line - 1 : line;
}
private convertTargetLineToClient(line: number): number {
if (this._targetLinesStartAt1) {
return this._clientLinesStartAt1 ? line : line - 1;
}
return this._clientLinesStartAt1 ? line + 1 : line;
}
}