From 0f4893299a16402491d9fd9e65555b64667b2968 Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Wed, 19 Sep 2018 00:04:29 +0200 Subject: [PATCH] check debugServer property first; improved fix for #58847 --- src/vs/workbench/api/node/extHost.api.impl.ts | 2 +- .../workbench/api/node/extHostDebugService.ts | 35 ++++++++++++++----- src/vs/workbench/parts/debug/node/debugger.ts | 34 ++++++++++-------- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index d74d4a4f9ff..949573f0753 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -120,7 +120,7 @@ export function createApiFactory( const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostDocumentsAndEditors)); const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands)); const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(rpcProtocol, extHostConfiguration, extHostLogService)); - const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(rpcProtocol, extHostWorkspace, extensionService, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService)); + const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(rpcProtocol, extHostWorkspace, extensionService, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService, extHostCommands)); const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService)); const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, new ExtHostSearch(rpcProtocol, schemeTransformer)); const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, new ExtHostTask(rpcProtocol, extHostWorkspace, extHostDocumentsAndEditors, extHostConfiguration)); diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index e0d68bbae18..5f82ffd36cd 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -16,7 +16,7 @@ import { IMainContext, IBreakpointsDeltaDto, ISourceMultiBreakpointDto, IFunctionBreakpointDto, IDebugSessionDto } from 'vs/workbench/api/node/extHost.protocol'; import * as vscode from 'vscode'; -import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint, DebugAdapterServer } from 'vs/workbench/api/node/extHostTypes'; +import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint, DebugAdapterServer, DebugAdapterExecutable } from 'vs/workbench/api/node/extHostTypes'; import { generateUuid } from 'vs/base/common/uuid'; import { DebugAdapter, SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter'; import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; @@ -32,6 +32,7 @@ import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalSer import { IDisposable } from 'vs/base/common/lifecycle'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { CancellationToken } from 'vs/base/common/cancellation'; +import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands'; export class ExtHostDebugService implements ExtHostDebugServiceShape { @@ -66,6 +67,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { private readonly _onDidChangeBreakpoints: Emitter; + private _aexCommands: Map; private _debugAdapters: Map; private _variableResolver: IConfigurationResolverService; @@ -79,9 +81,10 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { private _extensionService: ExtHostExtensionService, private _editorsService: ExtHostDocumentsAndEditors, private _configurationService: ExtHostConfiguration, - private _terminalService: ExtHostTerminalService + private _terminalService: ExtHostTerminalService, + private _commandService: ExtHostCommands ) { - + this._aexCommands = new Map(); this._handleCounter = 0; this._providerByHandle = new Map(); this._providerByType = new Map(); @@ -116,6 +119,9 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { // only debugger contributions with a "label" are considered a "main" debugger contribution if (dbg.type && dbg.label) { debugTypes.push(dbg.type); + if (dbg.adapterExecutableCommand) { + this._aexCommands.set(dbg.type, dbg.adapterExecutableCommand); + } } } } @@ -526,21 +532,34 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { // private & dto helpers private getAdapterDescriptor(debugConfigProvider, sessionDto: IDebugSessionDto, folderUri: UriComponents | undefined, config: vscode.DebugConfiguration): Thenable { + + // a "debugServer" attribute in the launch config takes precedence + if (typeof config.debugServer === 'number') { + return TPromise.wrap(new DebugAdapterServer(config.debugServer)); + } + if (debugConfigProvider) { + // try the proposed "provideDebugAdapter" API if (debugConfigProvider.provideDebugAdapter) { const adapterExecutable = DebugAdapter.platformAdapterExecutable(this._extensionService.getAllExtensionDescriptions(), config.type); return asThenable(() => debugConfigProvider.provideDebugAdapter(this.getSession(sessionDto), this.getFolder(folderUri), adapterExecutable, config, CancellationToken.None)); } - // deprecated + // try the deprecated "debugAdapterExecutable" API if (debugConfigProvider.debugAdapterExecutable) { return asThenable(() => debugConfigProvider.debugAdapterExecutable(this.getFolder(folderUri), CancellationToken.None)); } } - // fallback: use serverport or executable information from package.json - // TODO@AW support legacy command based mechanism - if (typeof config.debugServer === 'number') { - return TPromise.wrap(new DebugAdapterServer(config.debugServer)); + + // try deprecated command based extension API "adapterExecutableCommand" to determine the executable + const aex = this._aexCommands.get(config.type); + if (aex) { + const rootFolder = folderUri ? URI.revive(folderUri).toString() : undefined; + return this._commandService.executeCommand(aex, rootFolder).then((ae: { command: string, args: string[] }) => { + return new DebugAdapterExecutable(ae.command, ae.args || []); + }); } + + // fallback: use executable information from package.json return TPromise.wrap(DebugAdapter.platformAdapterExecutable(this._extensionService.getAllExtensionDescriptions(), config.type)); } diff --git a/src/vs/workbench/parts/debug/node/debugger.ts b/src/vs/workbench/parts/debug/node/debugger.ts index bff9b3c8424..608109ead79 100644 --- a/src/vs/workbench/parts/debug/node/debugger.ts +++ b/src/vs/workbench/parts/debug/node/debugger.ts @@ -58,28 +58,34 @@ export class Debugger implements IDebugger { private getAdapterDescriptor(session: IDebugSession, root: IWorkspaceFolder, config: IConfig): TPromise { - // try deprecated command based extension API to receive an executable - if (this.debuggerContribution.adapterExecutableCommand) { - return this.commandService.executeCommand(this.debuggerContribution.adapterExecutableCommand, root ? root.uri.toString() : undefined).then(ae => { - return { - type: 'executable', - command: ae.command, - args: ae.args || [] - }; + // a "debugServer" attribute in the launch config takes precedence + if (typeof config.debugServer === 'number') { + return TPromise.wrap({ + type: 'server', + port: config.debugServer }); } + // try the proposed and the deprecated "provideDebugAdapter" API return this.configurationManager.provideDebugAdapter(session, root ? root.uri : undefined, config).then(adapter => { + if (adapter) { return adapter; } - if (typeof config.debugServer === 'number') { - return { - type: 'server', - port: config.debugServer - }; + + // try deprecated command based extension API "adapterExecutableCommand" to determine the executable + if (this.debuggerContribution.adapterExecutableCommand) { + const rootFolder = root ? root.uri.toString() : undefined; + return this.commandService.executeCommand(this.debuggerContribution.adapterExecutableCommand, rootFolder).then((ae: { command: string, args: string[] }) => { + return { + type: 'executable', + command: ae.command, + args: ae.args || [] + }; + }); } - // fallback: use information from package.json + + // fallback: use executable information from package.json return DebugAdapter.platformAdapterExecutable(this.mergedExtensionDescriptions, this.type); }); } -- GitLab