-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add proposed debug API; fixes #28234
- Loading branch information
Showing
6 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/vs/workbench/api/electron-browser/mainThreadDebugService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 { IDisposable, dispose } from 'vs/base/common/lifecycle'; | ||
import { IDebugService, IProcess, IConfig } from 'vs/workbench/parts/debug/common/debug'; | ||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; | ||
import { TPromise } from 'vs/base/common/winjs.base'; | ||
import { ExtHostContext, ExtHostDebugServiceShape, MainThreadDebugServiceShape, DebugSessionUUID } from '../node/extHost.protocol'; | ||
|
||
export class MainThreadDebugService extends MainThreadDebugServiceShape { | ||
|
||
private _proxy: ExtHostDebugServiceShape; | ||
private _toDispose: IDisposable[]; | ||
|
||
constructor( | ||
@IThreadService threadService: IThreadService, | ||
@IDebugService private debugService: IDebugService | ||
) { | ||
super(); | ||
this._proxy = threadService.get(ExtHostContext.ExtHostDebugService); | ||
this._toDispose = []; | ||
this._toDispose.push(debugService.onDidEndProcess(proc => this._proxy.$acceptDebugSessionTerminated(<DebugSessionUUID>proc.getId(), proc.configuration.type, proc.name))); | ||
} | ||
|
||
public dispose(): void { | ||
this._toDispose = dispose(this._toDispose); | ||
} | ||
|
||
public $createDebugSession(configuration: IConfig): TPromise<DebugSessionUUID> { | ||
if (configuration.request !== 'launch' && configuration.request !== 'attach') { | ||
return TPromise.wrapError(`only 'launch' or 'attach' allowed for 'request' attribute`); | ||
} | ||
return this.debugService.createProcess(configuration).then(process => { | ||
if (process) { | ||
return <DebugSessionUUID>process.getId(); | ||
} | ||
return TPromise.wrapError('cannot create debug session'); | ||
}, err => { | ||
return TPromise.wrapError(err && err.message ? err.message : 'cannot create debug session'); | ||
}); | ||
} | ||
|
||
public $customDebugAdapterRequest(sessionId: DebugSessionUUID, request: string, args: any): TPromise<any> { | ||
const process = this._findProcessByUUID(sessionId); | ||
if (process) { | ||
return process.session.custom(request, args).then(response => { | ||
if (response.success) { | ||
return response.body; | ||
} else { | ||
return TPromise.wrapError(response.message); | ||
} | ||
}); | ||
} | ||
return TPromise.wrapError('debug session not found'); | ||
} | ||
|
||
private _findProcessByUUID(processId: DebugSessionUUID): IProcess | null { | ||
const processes = this.debugService.getModel().getProcesses(); | ||
const result = processes.filter(process => process.getId() === processId); | ||
if (result.length > 0) { | ||
return processes[0]; // there can only be one | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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<DebugSessionUUID, ExtHostDebugSession> = new Map<DebugSessionUUID, ExtHostDebugSession>(); | ||
|
||
private _onDidTerminateDebugSession: Emitter<vscode.DebugSession>; | ||
get onDidTerminateDebugSession(): Event<vscode.DebugSession> { return this._onDidTerminateDebugSession.event; } | ||
|
||
|
||
constructor(threadService: IThreadService) { | ||
super(); | ||
|
||
this._onDidTerminateDebugSession = new Emitter<vscode.DebugSession>(); | ||
this._debugServiceProxy = threadService.get(MainContext.MainThreadDebugService); | ||
} | ||
|
||
public createDebugSession(config: vscode.DebugConfiguration): TPromise<vscode.DebugSession> { | ||
|
||
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); | ||
} | ||
} | ||
|
||
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<any> { | ||
return this._debugServiceProxy.$customDebugAdapterRequest(this._id, command, args); | ||
} | ||
} |