From af809a59db7fc976d30457c0d66be1535fdcb83e Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Tue, 24 Oct 2017 13:03:05 +0200 Subject: [PATCH] API: expose debug console; fixes #36753 --- src/vs/vscode.proposed.d.ts | 27 +++++++++++++++++++ .../mainThreadDebugService.ts | 7 +++++ src/vs/workbench/api/node/extHost.api.impl.ts | 5 +++- src/vs/workbench/api/node/extHost.protocol.ts | 1 + .../workbench/api/node/extHostDebugService.ts | 24 ++++++++++++++++- 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 3ff70ed91db..5586bd1c124 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -190,4 +190,31 @@ declare module 'vscode' { } //#endregion + + /** + * Represents the debug console. + */ + export interface DebugConsole { + /** + * Append the given value to the debug console. + * + * @param value A string, falsy values will not be printed. + */ + append(value: string): void; + + /** + * Append the given value and a line feed character + * to the debug console. + * + * @param value A string, falsy values will be printed. + */ + appendLine(value: string): void; + } + + export namespace debug { + /** + * The [debug console](#DebugConsole) singleton. + */ + export let console: DebugConsole; + } } diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index af2d72759b5..8686e4f1483 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -11,6 +11,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { ExtHostContext, ExtHostDebugServiceShape, MainThreadDebugServiceShape, DebugSessionUUID, MainContext, IExtHostContext } from '../node/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; +import severity from 'vs/base/common/severity'; @extHostNamedCustomer(MainContext.MainThreadDebugService) export class MainThreadDebugService implements MainThreadDebugServiceShape { @@ -93,4 +94,10 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape { } return TPromise.wrapError(new Error('debug session not found')); } + + public $appendDebugConsole(value: string): TPromise { + // Use warning as severity to get the orange color for messages coming from the debug extension + this.debugService.logToRepl(value, severity.Warning); + return TPromise.as(undefined); + } } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 128eb4a907e..ea709951079 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -489,6 +489,9 @@ export function createApiFactory( get activeDebugSession() { return extHostDebugService.activeDebugSession; }, + get console() { + return extHostDebugService.debugConsole; + }, startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration) { return extHostDebugService.startDebugging(folder, nameOrConfig); }, @@ -506,7 +509,7 @@ export function createApiFactory( }, registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) { return extHostDebugService.registerDebugConfigurationProvider(debugType, provider); - }, + } }; // namespace: credentials diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 2619ab29fcb..2e14b41c060 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -404,6 +404,7 @@ export interface MainThreadDebugServiceShape extends IDisposable { $unregisterDebugConfigurationProvider(handle: number): TPromise; $startDebugging(folder: URI | undefined, nameOrConfig: string | vscode.DebugConfiguration): TPromise; $customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): TPromise; + $appendDebugConsole(value: string): TPromise; } export interface MainThreadCredentialsShape extends IDisposable { diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 71727e711d5..23c7a043199 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -40,6 +40,9 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { private _onDidReceiveDebugSessionCustomEvent: Emitter; get onDidReceiveDebugSessionCustomEvent(): Event { return this._onDidReceiveDebugSessionCustomEvent.event; } + private _debugConsole: ExtHostDebugConsole; + get debugConsole(): ExtHostDebugConsole { return this._debugConsole; } + constructor(mainContext: IMainContext, workspace: ExtHostWorkspace) { @@ -54,6 +57,8 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { this._onDidReceiveDebugSessionCustomEvent = new Emitter(); this._debugServiceProxy = mainContext.get(MainContext.MainThreadDebugService); + + this._debugConsole = new ExtHostDebugConsole(this._debugServiceProxy); } public registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider): vscode.Disposable { @@ -178,7 +183,7 @@ export class ExtHostDebugSession implements vscode.DebugSession { this._id = id; this._type = type; this._name = name; - }; + } public get id(): string { return this._id; @@ -196,3 +201,20 @@ export class ExtHostDebugSession implements vscode.DebugSession { return this._debugServiceProxy.$customDebugAdapterRequest(this._id, command, args); } } + +export class ExtHostDebugConsole implements vscode.DebugConsole { + + private _debugServiceProxy: MainThreadDebugServiceShape; + + constructor(proxy: MainThreadDebugServiceShape) { + this._debugServiceProxy = proxy; + } + + append(value: string): void { + this._debugServiceProxy.$appendDebugConsole(value); + } + + appendLine(value: string): void { + this.append(value + '\n'); + } +} -- GitLab