forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalDebugServerV2.ts
More file actions
48 lines (41 loc) · 1.86 KB
/
Copy pathLocalDebugServerV2.ts
File metadata and controls
48 lines (41 loc) · 1.86 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as net from 'net';
import { DebugSession } from 'vscode-debugadapter';
import { createDeferred } from '../../common/helpers';
import { ISocketServer } from '../../common/types';
import { IServiceContainer } from '../../ioc/types';
import { IDebugServer, LaunchRequestArguments } from '../Common/Contracts';
import { BaseDebugServer } from './BaseDebugServer';
export class LocalDebugServerV2 extends BaseDebugServer {
private socketServer?: ISocketServer;
constructor(debugSession: DebugSession, private args: LaunchRequestArguments, private serviceContainer: IServiceContainer) {
super(debugSession);
this.clientSocket = createDeferred<net.Socket>();
}
public Stop() {
if (this.socketServer) {
try {
this.socketServer.dispose();
// tslint:disable-next-line:no-empty
} catch { }
this.socketServer = undefined;
}
}
public async Start(): Promise<IDebugServer> {
const host = typeof this.args.host === 'string' && this.args.host.trim().length > 0 ? this.args.host!.trim() : 'localhost';
const socketServer = this.socketServer = this.serviceContainer.get<ISocketServer>(ISocketServer);
const port = await socketServer.Start({ port: this.args.port, host });
socketServer.client.then(socket => {
// This is required to prevent the launcher from aborting if the PTVSD process spits out any errors in stderr stream.
this.isRunning = true;
this.debugClientConnected.resolve(true);
this.clientSocket.resolve(socket);
}).catch(ex => {
this.debugClientConnected.reject(ex);
this.clientSocket.reject(ex);
});
return { port, host };
}
}