Skip to content

Commit 6551cf3

Browse files
committed
When producing types declarations, also emit the static types of the interfaces for TypeScript declarations.
This improves type checking on the declaration.
1 parent a533ebc commit 6551cf3

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

adapter/src/debugSession.ts

+32
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ export class CompletionItem implements DebugProtocol.CompletionItem {
139139
}
140140

141141
export class StoppedEvent extends Event implements DebugProtocol.StoppedEvent {
142+
event: 'stopped';
143+
142144
body: {
143145
reason: string;
144146
};
@@ -158,6 +160,8 @@ export class StoppedEvent extends Event implements DebugProtocol.StoppedEvent {
158160
}
159161

160162
export class ContinuedEvent extends Event implements DebugProtocol.ContinuedEvent {
163+
event: 'continued';
164+
161165
body: {
162166
threadId: number;
163167
};
@@ -175,12 +179,16 @@ export class ContinuedEvent extends Event implements DebugProtocol.ContinuedEven
175179
}
176180

177181
export class InitializedEvent extends Event implements DebugProtocol.InitializedEvent {
182+
event: 'initialized';
183+
178184
public constructor() {
179185
super('initialized');
180186
}
181187
}
182188

183189
export class TerminatedEvent extends Event implements DebugProtocol.TerminatedEvent {
190+
event: 'terminated';
191+
184192
public constructor(restart?: any) {
185193
super('terminated');
186194
if (typeof restart === 'boolean' || restart) {
@@ -193,6 +201,8 @@ export class TerminatedEvent extends Event implements DebugProtocol.TerminatedEv
193201
}
194202

195203
export class ExitedEvent extends Event implements DebugProtocol.ExitedEvent {
204+
event: 'exited';
205+
196206
body: {
197207
exitCode: number
198208
};
@@ -206,6 +216,8 @@ export class ExitedEvent extends Event implements DebugProtocol.ExitedEvent {
206216
}
207217

208218
export class OutputEvent extends Event implements DebugProtocol.OutputEvent {
219+
event: 'output';
220+
209221
body: {
210222
category: string,
211223
output: string,
@@ -225,6 +237,8 @@ export class OutputEvent extends Event implements DebugProtocol.OutputEvent {
225237
}
226238

227239
export class ThreadEvent extends Event implements DebugProtocol.ThreadEvent {
240+
event: 'thread';
241+
228242
body: {
229243
reason: string,
230244
threadId: number
@@ -240,6 +254,8 @@ export class ThreadEvent extends Event implements DebugProtocol.ThreadEvent {
240254
}
241255

242256
export class BreakpointEvent extends Event implements DebugProtocol.BreakpointEvent {
257+
event: 'breakpoint';
258+
243259
body: {
244260
reason: string,
245261
breakpoint: DebugProtocol.Breakpoint
@@ -255,6 +271,8 @@ export class BreakpointEvent extends Event implements DebugProtocol.BreakpointEv
255271
}
256272

257273
export class ModuleEvent extends Event implements DebugProtocol.ModuleEvent {
274+
event: 'module';
275+
258276
body: {
259277
reason: 'new' | 'changed' | 'removed',
260278
module: DebugProtocol.Module
@@ -270,6 +288,8 @@ export class ModuleEvent extends Event implements DebugProtocol.ModuleEvent {
270288
}
271289

272290
export class LoadedSourceEvent extends Event implements DebugProtocol.LoadedSourceEvent {
291+
event: 'loadedSource';
292+
273293
body: {
274294
reason: 'new' | 'changed' | 'removed',
275295
source: DebugProtocol.Source
@@ -285,6 +305,8 @@ export class LoadedSourceEvent extends Event implements DebugProtocol.LoadedSour
285305
}
286306

287307
export class CapabilitiesEvent extends Event implements DebugProtocol.CapabilitiesEvent {
308+
event: 'capabilities';
309+
288310
body: {
289311
capabilities: DebugProtocol.Capabilities
290312
};
@@ -298,6 +320,8 @@ export class CapabilitiesEvent extends Event implements DebugProtocol.Capabiliti
298320
}
299321

300322
export class ProgressStartEvent extends Event implements DebugProtocol.ProgressStartEvent {
323+
event: 'progressStart';
324+
301325
body: {
302326
progressId: string,
303327
title: string
@@ -316,6 +340,8 @@ export class ProgressStartEvent extends Event implements DebugProtocol.ProgressS
316340
}
317341

318342
export class ProgressUpdateEvent extends Event implements DebugProtocol.ProgressUpdateEvent {
343+
event: 'progressUpdate';
344+
319345
body: {
320346
progressId: string
321347
};
@@ -332,6 +358,8 @@ export class ProgressUpdateEvent extends Event implements DebugProtocol.Progress
332358
}
333359

334360
export class ProgressEndEvent extends Event implements DebugProtocol.ProgressEndEvent {
361+
event: 'progressEnd';
362+
335363
body: {
336364
progressId: string
337365
};
@@ -348,6 +376,8 @@ export class ProgressEndEvent extends Event implements DebugProtocol.ProgressEnd
348376
}
349377

350378
export class InvalidatedEvent extends Event implements DebugProtocol.InvalidatedEvent {
379+
event: 'invalidated';
380+
351381
body: {
352382
areas?: DebugProtocol.InvalidatedAreas[];
353383
threadId?: number;
@@ -371,6 +401,8 @@ export class InvalidatedEvent extends Event implements DebugProtocol.Invalidated
371401
}
372402

373403
export class MemoryEvent extends Event implements DebugProtocol.MemoryEvent {
404+
event: 'memory';
405+
374406
body: {
375407
memoryReference: string;
376408
offset: number;

adapter/src/messages.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Message implements DebugProtocol.ProtocolMessage {
1717
}
1818

1919
export class Response extends Message implements DebugProtocol.Response {
20+
type: 'response';
2021
request_seq: number;
2122
success: boolean;
2223
command: string;
@@ -35,6 +36,7 @@ export class Response extends Message implements DebugProtocol.Response {
3536
}
3637

3738
export class Event extends Message implements DebugProtocol.Event {
39+
type: 'event';
3840
event: string;
3941

4042
public constructor(event: string, body?: any) {

adapter/src/protocol.ts

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export class ProtocolServer extends ee.EventEmitter implements VSCodeDebugAdapte
111111
this._pendingRequests.delete(response.request_seq);
112112
clb(response);
113113
}
114+
} else if (msg.type === 'event') {
115+
this._emitEvent(<DebugProtocol.Event>msg)
114116
}
115117
}
116118

protocol/src/generator.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ function Module(moduleName: string, schema: IProtocol): string {
1818
s += line(" *--------------------------------------------------------------------------------------------*/");
1919
s += line();
2020

21-
//s += comment(schema.description);
2221
s += comment({ description: 'Declaration module describing the VS Code debug protocol.\nAuto-generated from json schema. Do not edit manually.'});
23-
22+
s += line();
23+
24+
s += comment({ description: schema.description });
2425
s += openBlock(`export declare module ${moduleName}`);
2526

2627
for (let typeName in schema.definitions) {
@@ -77,7 +78,7 @@ function Interface(interfaceName: string, definition: P.Definition, superType?:
7778

7879
let s = line();
7980

80-
s += comment({ description : desc });
81+
s += comment({ description: desc });
8182

8283
let x = `interface ${interfaceName}`;
8384
if (superType) {
@@ -247,11 +248,7 @@ function property(name: string, optional: boolean, prop: P.PropertyType): string
247248
s += comment(prop);
248249
const type = propertyType(prop);
249250
const propertyDef = `${name}${optional ? '?' : ''}: ${type}`;
250-
if (type[0] === '\'' && type[type.length-1] === '\'' && type.indexOf('|') < 0) {
251-
s += line(`// ${propertyDef};`);
252-
} else {
253-
s += line(`${propertyDef};`);
254-
}
251+
s += line(`${propertyDef};`);
255252
return s;
256253
}
257254

0 commit comments

Comments
 (0)