提交 8b84e962 编写于 作者: A Andre Weinand

support debugPort in EH

上级 211d2ea5
...@@ -61,9 +61,9 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb ...@@ -61,9 +61,9 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
this._toDispose.push(this.debugService.getConfigurationManager().registerDebugAdapterProvider(debugTypes, this)); this._toDispose.push(this.debugService.getConfigurationManager().registerDebugAdapterProvider(debugTypes, this));
} }
createDebugAdapter(debugType: string, adapterInfo): IDebugAdapter { createDebugAdapter(debugType: string, adapterInfo, debugPort: number): IDebugAdapter {
const handle = this._debugAdaptersHandleCounter++; const handle = this._debugAdaptersHandleCounter++;
const da = new ExtensionHostDebugAdapter(handle, this._proxy, debugType, adapterInfo); const da = new ExtensionHostDebugAdapter(handle, this._proxy, debugType, adapterInfo, debugPort);
this._debugAdapters.set(handle, da); this._debugAdapters.set(handle, da);
return da; return da;
} }
...@@ -262,7 +262,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb ...@@ -262,7 +262,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
*/ */
class ExtensionHostDebugAdapter extends AbstractDebugAdapter { class ExtensionHostDebugAdapter extends AbstractDebugAdapter {
constructor(private _handle: number, private _proxy: ExtHostDebugServiceShape, private _debugType: string, private _adapterExecutable: IAdapterExecutable | null) { constructor(private _handle: number, private _proxy: ExtHostDebugServiceShape, private _debugType: string, private _adapterExecutable: IAdapterExecutable | null, private _debugPort: number) {
super(); super();
} }
...@@ -275,7 +275,7 @@ class ExtensionHostDebugAdapter extends AbstractDebugAdapter { ...@@ -275,7 +275,7 @@ class ExtensionHostDebugAdapter extends AbstractDebugAdapter {
} }
public startSession(): TPromise<void> { public startSession(): TPromise<void> {
return this._proxy.$startDASession(this._handle, this._debugType, this._adapterExecutable); return this._proxy.$startDASession(this._handle, this._debugType, this._adapterExecutable, this._debugPort);
} }
public sendMessage(message: DebugProtocol.ProtocolMessage): void { public sendMessage(message: DebugProtocol.ProtocolMessage): void {
......
...@@ -821,7 +821,7 @@ export interface ISourceMultiBreakpointDto { ...@@ -821,7 +821,7 @@ export interface ISourceMultiBreakpointDto {
export interface ExtHostDebugServiceShape { export interface ExtHostDebugServiceShape {
$substituteVariables(folder: UriComponents | undefined, config: IConfig): TPromise<IConfig>; $substituteVariables(folder: UriComponents | undefined, config: IConfig): TPromise<IConfig>;
$runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments, config: ITerminalSettings): TPromise<void>; $runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments, config: ITerminalSettings): TPromise<void>;
$startDASession(handle: number, debugType: string, adapterExecutableInfo: IAdapterExecutable | null): TPromise<void>; $startDASession(handle: number, debugType: string, adapterExecutableInfo: IAdapterExecutable | null, debugPort: number): TPromise<void>;
$stopDASession(handle: number): TPromise<void>; $stopDASession(handle: number): TPromise<void>;
$sendDAMessage(handle: number, message: DebugProtocol.ProtocolMessage): TPromise<void>; $sendDAMessage(handle: number, message: DebugProtocol.ProtocolMessage): TPromise<void>;
$resolveDebugConfiguration(handle: number, folder: UriComponents | undefined, debugConfiguration: IConfig): TPromise<IConfig>; $resolveDebugConfiguration(handle: number, folder: UriComponents | undefined, debugConfiguration: IConfig): TPromise<IConfig>;
......
...@@ -17,11 +17,11 @@ import { ...@@ -17,11 +17,11 @@ import {
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint } from 'vs/workbench/api/node/extHostTypes'; import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint } from 'vs/workbench/api/node/extHostTypes';
import { generateUuid } from 'vs/base/common/uuid'; import { generateUuid } from 'vs/base/common/uuid';
import { DebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter'; import { DebugAdapter, StreamDebugAdapter, SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService'; import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
import { IAdapterExecutable, ITerminalSettings, IDebuggerContribution, IConfig } from 'vs/workbench/parts/debug/common/debug'; import { IAdapterExecutable, ITerminalSettings, IDebuggerContribution, IConfig, IDebugAdapter } from 'vs/workbench/parts/debug/common/debug';
import { getTerminalLauncher } from 'vs/workbench/parts/debug/node/terminals'; import { getTerminalLauncher } from 'vs/workbench/parts/debug/node/terminals';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { VariableResolver } from 'vs/workbench/services/configurationResolver/node/variableResolver'; import { VariableResolver } from 'vs/workbench/services/configurationResolver/node/variableResolver';
...@@ -62,7 +62,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { ...@@ -62,7 +62,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
private readonly _onDidChangeBreakpoints: Emitter<vscode.BreakpointsChangeEvent>; private readonly _onDidChangeBreakpoints: Emitter<vscode.BreakpointsChangeEvent>;
private _debugAdapters: Map<number, DebugAdapter>; private _debugAdapters: Map<number, IDebugAdapter>;
private _variableResolver: IConfigurationResolverService; private _variableResolver: IConfigurationResolverService;
...@@ -133,22 +133,41 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { ...@@ -133,22 +133,41 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
return asWinJsPromise(token => DebugAdapter.substituteVariables(folder, config, this._variableResolver)); return asWinJsPromise(token => DebugAdapter.substituteVariables(folder, config, this._variableResolver));
} }
public $startDASession(handle: number, debugType: string, adpaterExecutable: IAdapterExecutable | null): TPromise<void> { public $startDASession(handle: number, debugType: string, adpaterExecutable: IAdapterExecutable | null, debugPort: number): TPromise<void> {
const mythis = this; const mythis = this;
const da = new class extends DebugAdapter { let da: StreamDebugAdapter = null;
// DA -> VS Code if (debugPort > 0) {
public acceptMessage(message: DebugProtocol.ProtocolMessage) { da = new class extends SocketDebugAdapter {
convertToVSCPaths(message, source => {
if (paths.isAbsolute(source.path)) { // DA -> VS Code
(<any>source).path = URI.file(source.path); public acceptMessage(message: DebugProtocol.ProtocolMessage) {
} convertToVSCPaths(message, source => {
}); if (paths.isAbsolute(source.path)) {
mythis._debugServiceProxy.$acceptDAMessage(handle, message); (<any>source).path = URI.file(source.path);
} }
});
mythis._debugServiceProxy.$acceptDAMessage(handle, message);
}
}(debugPort);
}(debugType, adpaterExecutable, this._extensionService.getAllExtensionDescriptions()); } else {
da = new class extends DebugAdapter {
// DA -> VS Code
public acceptMessage(message: DebugProtocol.ProtocolMessage) {
convertToVSCPaths(message, source => {
if (paths.isAbsolute(source.path)) {
(<any>source).path = URI.file(source.path);
}
});
mythis._debugServiceProxy.$acceptDAMessage(handle, message);
}
}(debugType, adpaterExecutable, this._extensionService.getAllExtensionDescriptions());
}
this._debugAdapters.set(handle, da); this._debugAdapters.set(handle, da);
da.onError(err => this._debugServiceProxy.$acceptDAError(handle, err.name, err.message, err.stack)); da.onError(err => this._debugServiceProxy.$acceptDAError(handle, err.name, err.message, err.stack));
......
...@@ -406,7 +406,7 @@ export interface IDebugAdapter extends IDisposable { ...@@ -406,7 +406,7 @@ export interface IDebugAdapter extends IDisposable {
} }
export interface IDebugAdapterProvider extends ITerminalLauncher { export interface IDebugAdapterProvider extends ITerminalLauncher {
createDebugAdapter(debugType: string, adapterInfo: IAdapterExecutable | null): IDebugAdapter; createDebugAdapter(debugType: string, adapterInfo: IAdapterExecutable | null, debugPort: number): IDebugAdapter;
substituteVariables(folder: IWorkspaceFolder, config: IConfig): TPromise<IConfig>; substituteVariables(folder: IWorkspaceFolder, config: IConfig): TPromise<IConfig>;
} }
...@@ -506,7 +506,7 @@ export interface IConfigurationManager { ...@@ -506,7 +506,7 @@ export interface IConfigurationManager {
debugAdapterExecutable(folderUri: uri | undefined, type: string): TPromise<IAdapterExecutable | undefined>; debugAdapterExecutable(folderUri: uri | undefined, type: string): TPromise<IAdapterExecutable | undefined>;
registerDebugAdapterProvider(debugTypes: string[], debugAdapterLauncher: IDebugAdapterProvider): IDisposable; registerDebugAdapterProvider(debugTypes: string[], debugAdapterLauncher: IDebugAdapterProvider): IDisposable;
createDebugAdapter(debugType: string, adapterExecutable: IAdapterExecutable | null): IDebugAdapter | undefined; createDebugAdapter(debugType: string, adapterExecutable: IAdapterExecutable | null, debugPort?: number): IDebugAdapter | undefined;
substituteVariables(debugType: string, folder: IWorkspaceFolder, config: IConfig): TPromise<IConfig>; substituteVariables(debugType: string, folder: IWorkspaceFolder, config: IConfig): TPromise<IConfig>;
runInTerminal(debugType: string, args: DebugProtocol.RunInTerminalRequestArguments, config: ITerminalSettings): TPromise<void>; runInTerminal(debugType: string, args: DebugProtocol.RunInTerminalRequestArguments, config: ITerminalSettings): TPromise<void>;
} }
......
...@@ -140,10 +140,10 @@ export class ConfigurationManager implements IConfigurationManager { ...@@ -140,10 +140,10 @@ export class ConfigurationManager implements IConfigurationManager {
return this.debugAdapterProviders.get(type); return this.debugAdapterProviders.get(type);
} }
public createDebugAdapter(debugType: string, adapterExecutable: IAdapterExecutable): IDebugAdapter | undefined { public createDebugAdapter(debugType: string, adapterExecutable: IAdapterExecutable, debugPort: number): IDebugAdapter | undefined {
let dap = this.getDebugAdapterProvider(debugType); let dap = this.getDebugAdapterProvider(debugType);
if (dap) { if (dap) {
return dap.createDebugAdapter(debugType, adapterExecutable); return dap.createDebugAdapter(debugType, adapterExecutable, debugPort);
} }
return undefined; return undefined;
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import * as net from 'net';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import * as objects from 'vs/base/common/objects'; import * as objects from 'vs/base/common/objects';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
...@@ -16,8 +15,8 @@ import { Debugger } from 'vs/workbench/parts/debug/node/debugger'; ...@@ -16,8 +15,8 @@ import { Debugger } from 'vs/workbench/parts/debug/node/debugger';
import { IOutputService } from 'vs/workbench/parts/output/common/output'; import { IOutputService } from 'vs/workbench/parts/output/common/output';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { StreamDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
import { formatPII } from 'vs/workbench/parts/debug/common/debugUtils'; import { formatPII } from 'vs/workbench/parts/debug/common/debugUtils';
import { SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
export interface SessionExitedEvent extends debug.DebugEvent { export interface SessionExitedEvent extends debug.DebugEvent {
...@@ -34,36 +33,6 @@ export interface SessionTerminatedEvent extends debug.DebugEvent { ...@@ -34,36 +33,6 @@ export interface SessionTerminatedEvent extends debug.DebugEvent {
}; };
} }
export class SocketDebugAdapter extends StreamDebugAdapter {
private socket: net.Socket;
constructor(private host: string, private port: number) {
super();
}
startSession(): TPromise<void> {
return new TPromise<void>((c, e) => {
this.socket = net.createConnection(this.port, this.host, () => {
this.connect(this.socket, <any>this.socket);
c(null);
});
this.socket.on('error', (err: any) => {
e(err);
});
this.socket.on('close', () => this._onExit.fire(0));
});
}
stopSession(): TPromise<void> {
if (this.socket !== null) {
this.socket.end();
this.socket = undefined;
}
return void 0;
}
}
export class RawDebugSession implements debug.IRawSession { export class RawDebugSession implements debug.IRawSession {
private debugAdapter: debug.IDebugAdapter; private debugAdapter: debug.IDebugAdapter;
...@@ -186,11 +155,7 @@ export class RawDebugSession implements debug.IRawSession { ...@@ -186,11 +155,7 @@ export class RawDebugSession implements debug.IRawSession {
private startSession(): TPromise<void> { private startSession(): TPromise<void> {
const debugAdapterP = this.debugServerPort return this._debugger.createDebugAdapter(this.root, this.outputService, this.debugServerPort).then(debugAdapter => {
? TPromise.as(new SocketDebugAdapter('127.0.0.1', this.debugServerPort))
: this._debugger.createDebugAdapter(this.root, this.outputService);
return debugAdapterP.then(debugAdapter => {
this.debugAdapter = debugAdapter; this.debugAdapter = debugAdapter;
......
...@@ -7,6 +7,7 @@ import * as fs from 'fs'; ...@@ -7,6 +7,7 @@ import * as fs from 'fs';
import * as cp from 'child_process'; import * as cp from 'child_process';
import * as stream from 'stream'; import * as stream from 'stream';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import * as net from 'net';
import * as paths from 'vs/base/common/paths'; import * as paths from 'vs/base/common/paths';
import * as strings from 'vs/base/common/strings'; import * as strings from 'vs/base/common/strings';
import * as objects from 'vs/base/common/objects'; import * as objects from 'vs/base/common/objects';
...@@ -215,6 +216,39 @@ export abstract class StreamDebugAdapter extends AbstractDebugAdapter { ...@@ -215,6 +216,39 @@ export abstract class StreamDebugAdapter extends AbstractDebugAdapter {
} }
} }
/**
* An implementation that connects to a debug adapter via a socket.
*/
export class SocketDebugAdapter extends StreamDebugAdapter {
private socket: net.Socket;
constructor(private port: number, private host = '127.0.0.1') {
super();
}
startSession(): TPromise<void> {
return new TPromise<void>((c, e) => {
this.socket = net.createConnection(this.port, this.host, () => {
this.connect(this.socket, <any>this.socket);
c(null);
});
this.socket.on('error', (err: any) => {
e(err);
});
this.socket.on('close', () => this._onExit.fire(0));
});
}
stopSession(): TPromise<void> {
if (this.socket !== null) {
this.socket.end();
this.socket = undefined;
}
return void 0;
}
}
/** /**
* An implementation that launches the debug adapter as a separate process and communicates via stdin/stdout. * An implementation that launches the debug adapter as a separate process and communicates via stdin/stdout.
*/ */
......
...@@ -16,7 +16,7 @@ import { IExtensionDescription } from 'vs/workbench/services/extensions/common/e ...@@ -16,7 +16,7 @@ import { IExtensionDescription } from 'vs/workbench/services/extensions/common/e
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { IOutputService } from 'vs/workbench/parts/output/common/output'; import { IOutputService } from 'vs/workbench/parts/output/common/output';
import { DebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter'; import { DebugAdapter, SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService'; import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import uri from 'vs/base/common/uri'; import uri from 'vs/base/common/uri';
...@@ -38,13 +38,17 @@ export class Debugger { ...@@ -38,13 +38,17 @@ export class Debugger {
public hasConfigurationProvider = false; public hasConfigurationProvider = false;
public createDebugAdapter(root: IWorkspaceFolder, outputService: IOutputService): TPromise<IDebugAdapter> { public createDebugAdapter(root: IWorkspaceFolder, outputService: IOutputService, debugPort?: number): TPromise<IDebugAdapter> {
return this.getAdapterExecutable(root).then(adapterExecutable => { return this.getAdapterExecutable(root).then(adapterExecutable => {
const debugConfigs = this.configurationService.getValue<IDebugConfiguration>('debug'); const debugConfigs = this.configurationService.getValue<IDebugConfiguration>('debug');
if (debugConfigs.extensionHostDebugAdapter) { if (debugConfigs.extensionHostDebugAdapter) {
return this.configurationManager.createDebugAdapter(this.type, adapterExecutable); return this.configurationManager.createDebugAdapter(this.type, adapterExecutable, debugPort);
} else { } else {
return new DebugAdapter(this.type, adapterExecutable, this.mergedExtensionDescriptions, outputService); if (debugPort) {
return new SocketDebugAdapter(debugPort);
} else {
return new DebugAdapter(this.type, adapterExecutable, this.mergedExtensionDescriptions, outputService);
}
} }
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册