Skip to content

Commit 2edceb5

Browse files
committed
Refactor TypeScript declarations
1 parent a45f3e8 commit 2edceb5

12 files changed

+181
-182
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import {DebugProtocol} from 'vscode-debugprotocol';
2+
3+
declare module 'vscode-debugprotocol' {
4+
namespace DebugProtocol {
5+
interface ILaunchRequestArgs extends DebugProtocol.LaunchRequestArguments {
6+
platform: string;
7+
appRoot?: string;
8+
runtimeArgs?: string[];
9+
runtimeExecutable?: string;
10+
stopOnEntry?: boolean;
11+
sourceMaps?: boolean;
12+
diagnosticLogging?: boolean;
13+
emulator?:boolean;
14+
request: string;
15+
tnsArgs?: string[];
16+
tnsOutput?: string;
17+
rebuild?: boolean;
18+
syncAllFiles?: boolean;
19+
nativescriptCliPath?: string;
20+
}
21+
22+
interface IAttachRequestArgs extends DebugProtocol.AttachRequestArguments {
23+
platform: string;
24+
appRoot?: string;
25+
sourceMaps?: boolean;
26+
diagnosticLogging?: boolean;
27+
emulator?:boolean;
28+
request: string;
29+
tnsArgs?: string[];
30+
tnsOutput?: string;
31+
nativescriptCliPath?: string;
32+
}
33+
34+
interface ISetBreakpointsArgs extends DebugProtocol.SetBreakpointsArguments {
35+
/** DebugProtocol does not send cols, maybe it will someday, but this is used internally when a location is sourcemapped */
36+
cols?: number[];
37+
authoredPath?: string;
38+
}
39+
40+
interface IBreakpoint extends DebugProtocol.Breakpoint {
41+
column?: number;
42+
}
43+
44+
/*
45+
* The ResponseBody interfaces are copied from debugProtocol.d.ts which defines these inline in the Response interfaces.
46+
* They should always match those interfaces, see the original for comments.
47+
*/
48+
interface ISetBreakpointsResponseBody {
49+
breakpoints: IBreakpoint[];
50+
}
51+
52+
interface ISourceResponseBody {
53+
content: string;
54+
}
55+
56+
interface IThreadsResponseBody {
57+
threads: DebugProtocol.Thread[];
58+
}
59+
60+
interface IStackTraceResponseBody {
61+
stackFrames: DebugProtocol.StackFrame[];
62+
}
63+
64+
interface IScopesResponseBody {
65+
scopes: DebugProtocol.Scope[];
66+
}
67+
68+
interface IVariablesResponseBody {
69+
variables: DebugProtocol.Variable[];
70+
}
71+
72+
interface IEvaluateResponseBody {
73+
result: string;
74+
variablesReference: number;
75+
}
76+
77+
type PromiseOrNot<T> = T | Promise<T>;
78+
79+
interface IDebugAdapter {
80+
registerEventHandler(eventHandler: (event: DebugProtocol.Event) => void): void;
81+
82+
initialize(args: DebugProtocol.InitializeRequestArguments): PromiseOrNot<DebugProtocol.Capabilities>;
83+
launch(args: ILaunchRequestArgs): PromiseOrNot<void>;
84+
configurationDone(args: DebugProtocol.ConfigurationDoneArguments): void;
85+
disconnect(): PromiseOrNot<void>;
86+
attach(args: IAttachRequestArgs): PromiseOrNot<void>;
87+
setBreakpoints(args: DebugProtocol.SetBreakpointsArguments): PromiseOrNot<ISetBreakpointsResponseBody>;
88+
setExceptionBreakpoints(args: DebugProtocol.SetExceptionBreakpointsArguments): PromiseOrNot<void>;
89+
90+
continue(): PromiseOrNot<void>;
91+
next(): PromiseOrNot<void>;
92+
stepIn(): PromiseOrNot<void>;
93+
stepOut(): PromiseOrNot<void>;
94+
pause(): PromiseOrNot<void>;
95+
96+
stackTrace(args: DebugProtocol.StackTraceArguments): PromiseOrNot<IStackTraceResponseBody>;
97+
scopes(args: DebugProtocol.ScopesArguments): PromiseOrNot<IScopesResponseBody>;
98+
variables(args: DebugProtocol.VariablesArguments): PromiseOrNot<IVariablesResponseBody>;
99+
source(args: DebugProtocol.SourceArguments): PromiseOrNot<ISourceResponseBody>;
100+
threads(): PromiseOrNot<IThreadsResponseBody>;
101+
evaluate(args: DebugProtocol.EvaluateArguments): PromiseOrNot<IEvaluateResponseBody>;
102+
}
103+
104+
interface IDebugTransformer {
105+
initialize?(args: DebugProtocol.InitializeRequestArguments, requestSeq?: number): PromiseOrNot<void>;
106+
launch?(args: ILaunchRequestArgs, requestSeq?: number): PromiseOrNot<void>;
107+
attach?(args: IAttachRequestArgs, requestSeq?: number): PromiseOrNot<void>;
108+
setBreakpoints?(args: DebugProtocol.SetBreakpointsArguments, requestSeq?: number): PromiseOrNot<void>;
109+
setExceptionBreakpoints?(args: DebugProtocol.SetExceptionBreakpointsArguments, requestSeq?: number): PromiseOrNot<void>;
110+
111+
stackTrace?(args: DebugProtocol.StackTraceArguments, requestSeq?: number): PromiseOrNot<void>;
112+
scopes?(args: DebugProtocol.ScopesArguments, requestSeq?: number): PromiseOrNot<void>;
113+
variables?(args: DebugProtocol.VariablesArguments, requestSeq?: number): PromiseOrNot<void>;
114+
source?(args: DebugProtocol.SourceArguments, requestSeq?: number): PromiseOrNot<void>;
115+
evaluate?(args: DebugProtocol.EvaluateArguments, requestSeq?: number): PromiseOrNot<void>;
116+
117+
setBreakpointsResponse?(response: ISetBreakpointsResponseBody, requestSeq?: number): PromiseOrNot<void>;
118+
stackTraceResponse?(response: IStackTraceResponseBody, requestSeq?: number): PromiseOrNot<void>;
119+
scopesResponse?(response: IScopesResponseBody, requestSeq?: number): PromiseOrNot<void>;
120+
variablesResponse?(response: IVariablesResponseBody, requestSeq?: number): PromiseOrNot<void>;
121+
sourceResponse?(response: ISourceResponseBody, requestSeq?: number): PromiseOrNot<void>;
122+
threadsResponse?(response: IThreadsResponseBody, requestSeq?: number): PromiseOrNot<void>;
123+
evaluateResponse?(response: IEvaluateResponseBody, requestSeq?: number): PromiseOrNot<void>;
124+
125+
scriptParsed?(event: DebugProtocol.Event);
126+
}
127+
}
128+
}

src/debug-adapter/adapter/adapterProxy.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
import * as utils from '../utilities';
66
import {DebugProtocol} from 'vscode-debugprotocol';
7-
import {IDebugTransformer, IDebugAdapter} from '../WebKitAdapterInterfaces';
87

98
export type EventHandler = (event: DebugProtocol.Event) => void;
109

1110
export class AdapterProxy {
1211
private static INTERNAL_EVENTS = ['scriptParsed', 'clearClientContext', 'clearTargetContext'];
1312

14-
public constructor(private _requestTransformers: IDebugTransformer[], private _debugAdapter: IDebugAdapter, private _eventHandler: EventHandler) {
13+
public constructor(private _requestTransformers: DebugProtocol.IDebugTransformer[], private _debugAdapter: DebugProtocol.IDebugAdapter, private _eventHandler: EventHandler) {
1514
this._debugAdapter.registerEventHandler(event => this.onAdapterEvent(event));
1615
}
1716

src/debug-adapter/adapter/lineNumberTransformer.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
*--------------------------------------------------------*/
44

55
import {DebugProtocol} from 'vscode-debugprotocol';
6-
import {IDebugTransformer, ISetBreakpointsResponseBody, IStackTraceResponseBody} from '../WebKitAdapterInterfaces';
76

87
/**
98
* Converts from 1 based lines on the client side to 0 based lines on the target side
109
*/
11-
export class LineNumberTransformer implements IDebugTransformer {
10+
export class LineNumberTransformer implements DebugProtocol.IDebugTransformer {
1211
private _targetLinesStartAt1: boolean;
1312
private _clientLinesStartAt1: boolean;
1413

@@ -24,11 +23,11 @@ export class LineNumberTransformer implements IDebugTransformer {
2423
args.lines = args.lines.map(line => this.convertClientLineToTarget(line));
2524
}
2625

27-
public setBreakpointsResponse(response: ISetBreakpointsResponseBody): void {
26+
public setBreakpointsResponse(response: DebugProtocol.ISetBreakpointsResponseBody): void {
2827
response.breakpoints.forEach(bp => bp.line = this.convertTargetLineToClient(bp.line));
2928
}
3029

31-
public stackTraceResponse(response: IStackTraceResponseBody): void {
30+
public stackTraceResponse(response: DebugProtocol.IStackTraceResponseBody): void {
3231
response.stackFrames.forEach(frame => frame.line = this.convertTargetLineToClient(frame.line));
3332
}
3433

src/debug-adapter/adapter/pathTransformer.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,36 @@
55
import * as utils from '../utilities';
66
import {DebugProtocol} from 'vscode-debugprotocol';
77
import * as path from 'path';
8-
import {ISetBreakpointsArgs, IDebugTransformer, ILaunchRequestArgs, IAttachRequestArgs, IStackTraceResponseBody} from '../WebKitAdapterInterfaces';
98

109
interface IPendingBreakpoint {
1110
resolve: () => void;
1211
reject: (e: Error) => void;
13-
args: ISetBreakpointsArgs;
12+
args: DebugProtocol.ISetBreakpointsArgs;
1413
}
1514

1615
/**
1716
* Converts a local path from Code to a path on the target.
1817
*/
19-
export class PathTransformer implements IDebugTransformer {
18+
export class PathTransformer implements DebugProtocol.IDebugTransformer {
2019
private _webRoot: string;
2120
private _platform: string;
2221
private _clientPathToWebkitUrl = new Map<string, string>();
2322
private _webkitUrlToClientPath = new Map<string, string>();
2423
private _pendingBreakpointsByPath = new Map<string, IPendingBreakpoint>();
2524
private inferedDeviceRoot :string = null;
2625

27-
public launch(args: ILaunchRequestArgs): void {
26+
public launch(args: DebugProtocol.ILaunchRequestArgs): void {
2827
this._webRoot = utils.getAppRoot(args);
2928
this._platform = args.platform;
3029
this.inferedDeviceRoot = (this._platform === 'ios') ? 'file://' : this.inferedDeviceRoot;
3130
}
3231

33-
public attach(args: IAttachRequestArgs): void {
32+
public attach(args: DebugProtocol.IAttachRequestArgs): void {
3433
this._webRoot = utils.getAppRoot(args);
3534
this._platform = args.platform;
3635
}
3736

38-
public setBreakpoints(args: ISetBreakpointsArgs): Promise<void> {
37+
public setBreakpoints(args: DebugProtocol.ISetBreakpointsArgs): Promise<void> {
3938
return new Promise<void>((resolve, reject) => {
4039
if (!args.source.path) {
4140
resolve();
@@ -125,7 +124,7 @@ export class PathTransformer implements IDebugTransformer {
125124
}
126125
}
127126

128-
public stackTraceResponse(response: IStackTraceResponseBody): void {
127+
public stackTraceResponse(response: DebugProtocol.IStackTraceResponseBody): void {
129128
response.stackFrames.forEach(frame => {
130129
// Try to resolve the url to a path in the workspace. If it's not in the workspace,
131130
// just use the script.url as-is. It will be resolved or cleared by the SourceMapTransformer.

src/debug-adapter/adapter/sourceMaps/sourceMapTransformer.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,40 @@ import * as path from 'path';
66
import * as fs from 'fs';
77
import {DebugProtocol} from 'vscode-debugprotocol';
88
import {ISourceMaps, SourceMaps} from './sourceMaps';
9-
import {ISetBreakpointsArgs, IDebugTransformer, ILaunchRequestArgs, IAttachRequestArgs, ISetBreakpointsResponseBody, IStackTraceResponseBody} from '../../WebKitAdapterInterfaces';
109
import * as utils from '../../utilities';
1110

1211
interface IPendingBreakpoint {
1312
resolve: () => void;
1413
reject: (e: Error) => void;
15-
args: ISetBreakpointsArgs;
14+
args: DebugProtocol.ISetBreakpointsArgs;
1615
requestSeq: number;
1716
}
1817

1918
/**
2019
* If sourcemaps are enabled, converts from source files on the client side to runtime files on the target side
2120
*/
22-
export class SourceMapTransformer implements IDebugTransformer {
21+
export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
2322
private _sourceMaps: ISourceMaps;
24-
private _requestSeqToSetBreakpointsArgs: Map<number, ISetBreakpointsArgs>;
23+
private _requestSeqToSetBreakpointsArgs: Map<number, DebugProtocol.ISetBreakpointsArgs>;
2524
private _allRuntimeScriptPaths: Set<string>;
2625
private _pendingBreakpointsByPath = new Map<string, IPendingBreakpoint>();
2726
private _webRoot: string;
2827
private _authoredPathsToMappedBPLines: Map<string, number[]>;
2928
private _authoredPathsToMappedBPCols: Map<string, number[]>;
3029

31-
public launch(args: ILaunchRequestArgs): void {
30+
public launch(args: DebugProtocol.ILaunchRequestArgs): void {
3231
this.init(args);
3332
}
3433

35-
public attach(args: IAttachRequestArgs): void {
34+
public attach(args: DebugProtocol.IAttachRequestArgs): void {
3635
this.init(args);
3736
}
3837

39-
private init(args: ILaunchRequestArgs | IAttachRequestArgs): void {
38+
private init(args: DebugProtocol.ILaunchRequestArgs | DebugProtocol.IAttachRequestArgs): void {
4039
if (args.sourceMaps) {
4140
this._webRoot = utils.getAppRoot(args);
4241
this._sourceMaps = new SourceMaps(this._webRoot);
43-
this._requestSeqToSetBreakpointsArgs = new Map<number, ISetBreakpointsArgs>();
42+
this._requestSeqToSetBreakpointsArgs = new Map<number, DebugProtocol.ISetBreakpointsArgs>();
4443
this._allRuntimeScriptPaths = new Set<string>();
4544
this._authoredPathsToMappedBPLines = new Map<string, number[]>();
4645
this._authoredPathsToMappedBPCols = new Map<string, number[]>();
@@ -54,7 +53,7 @@ export class SourceMapTransformer implements IDebugTransformer {
5453
/**
5554
* Apply sourcemapping to the setBreakpoints request path/lines
5655
*/
57-
public setBreakpoints(args: ISetBreakpointsArgs, requestSeq: number): Promise<void> {
56+
public setBreakpoints(args: DebugProtocol.ISetBreakpointsArgs, requestSeq: number): Promise<void> {
5857
return new Promise<void>((resolve, reject) => {
5958
if (this._sourceMaps && args.source.path && path.extname(args.source.path) !== ".js") {
6059
const argsPath = args.source.path;
@@ -120,7 +119,7 @@ export class SourceMapTransformer implements IDebugTransformer {
120119
/**
121120
* Apply sourcemapping back to authored files from the response
122121
*/
123-
public setBreakpointsResponse(response: ISetBreakpointsResponseBody, requestSeq: number): void {
122+
public setBreakpointsResponse(response: DebugProtocol.ISetBreakpointsResponseBody, requestSeq: number): void {
124123
if (this._sourceMaps && this._requestSeqToSetBreakpointsArgs.has(requestSeq)) {
125124
const args = this._requestSeqToSetBreakpointsArgs.get(requestSeq);
126125
if (args.authoredPath) {
@@ -154,7 +153,7 @@ export class SourceMapTransformer implements IDebugTransformer {
154153
/**
155154
* Apply sourcemapping to the stacktrace response
156155
*/
157-
public stackTraceResponse(response: IStackTraceResponseBody): void {
156+
public stackTraceResponse(response: DebugProtocol.IStackTraceResponseBody): void {
158157
if (this._sourceMaps) {
159158
response.stackFrames.forEach(stackFrame => {
160159
const mapped = this._sourceMaps.MapToSource(stackFrame.source.path, stackFrame.line, stackFrame.column);

src/debug-adapter/connection/androidConnection.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as http from 'http';
22
import {EventEmitter} from 'events';
3-
import * as utils from '../utilities';
43
import {Logger} from '../utilities';
54
import * as Net from 'net';
65
import * as ns from '../../services/NsCliService';

src/debug-adapter/utilities.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as os from 'os';
99
import * as fs from 'fs';
1010
import * as url from 'url';
1111
import * as path from 'path';
12-
import {ILaunchRequestArgs, IAttachRequestArgs} from './WebKitAdapterInterfaces';
12+
import {DebugProtocol} from 'vscode-debugprotocol';
1313

1414
const DEFAULT_CHROME_PATH = {
1515
OSX: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
@@ -458,7 +458,7 @@ export function errP(msg: any): Promise<any> {
458458
/**
459459
* Calculates the appRoot from a launch/attach request. The appRoot is the root directory of the NativeScript app.
460460
*/
461-
export function getAppRoot(args: ILaunchRequestArgs | IAttachRequestArgs): string {
461+
export function getAppRoot(args: DebugProtocol.ILaunchRequestArgs | DebugProtocol.IAttachRequestArgs): string {
462462
return (args.appRoot && path.isAbsolute(args.appRoot)) ? args.appRoot : '';
463463
}
464464

0 commit comments

Comments
 (0)