/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import { TPromise } from 'vs/base/common/winjs.base'; import Event, { Emitter } from 'vs/base/common/event'; import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; import { MainContext, MainThreadDebugServiceShape, ExtHostDebugServiceShape, DebugSessionUUID } from 'vs/workbench/api/node/extHost.protocol'; import * as vscode from 'vscode'; export class ExtHostDebugService extends ExtHostDebugServiceShape { private _debugServiceProxy: MainThreadDebugServiceShape; private _debugSessions: Map = new Map(); private _onDidTerminateDebugSession: Emitter; get onDidTerminateDebugSession(): Event { return this._onDidTerminateDebugSession.event; } private _onDidChangeActiveDebugSession: Emitter; get onDidChangeActiveDebugSession(): Event { return this._onDidChangeActiveDebugSession.event; } private _activeDebugSession: vscode.DebugSession | undefined; get activeDebugSession(): vscode.DebugSession | undefined { return this._activeDebugSession; } constructor(threadService: IThreadService) { super(); this._onDidTerminateDebugSession = new Emitter(); this._onDidChangeActiveDebugSession = new Emitter(); this._debugServiceProxy = threadService.get(MainContext.MainThreadDebugService); } public createDebugSession(config: vscode.DebugConfiguration): TPromise { return this._debugServiceProxy.$createDebugSession(config).then((id: DebugSessionUUID) => { const debugSession = new ExtHostDebugSession(this._debugServiceProxy, id, config.type, config.name); this._debugSessions.set(id, debugSession); return debugSession; }); } public $acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void { let debugSession = this._debugSessions.get(id); if (!debugSession) { debugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name); } this._onDidTerminateDebugSession.fire(debugSession); this._debugSessions.delete(id); } public $acceptDebugSessionActiveChanged(id: DebugSessionUUID | undefined, type?: string, name?: string): void { if (id) { this._activeDebugSession = this._debugSessions.get(id); if (!this._activeDebugSession) { this._activeDebugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name); } } else { this._activeDebugSession = undefined; } this._onDidChangeActiveDebugSession.fire(this._activeDebugSession); } } export class ExtHostDebugSession implements vscode.DebugSession { private _debugServiceProxy: MainThreadDebugServiceShape; private _id: DebugSessionUUID; private _type: string; private _name: string; constructor(proxy: MainThreadDebugServiceShape, id: DebugSessionUUID, type: string, name: string) { this._debugServiceProxy = proxy; this._id = id; this._type = type; this._name = name; }; public get type(): string { return this._type; } public get name(): string { return this._name; } public customRequest(command: string, args: any): Thenable { return this._debugServiceProxy.$customDebugAdapterRequest(this._id, command, args); } }