From c48845126e2c32e3239ec84a2ffda3023e3971f1 Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Tue, 6 Nov 2018 12:07:45 +0100 Subject: [PATCH] clone DAP messages properly --- .../electron-browser/mainThreadDebugService.ts | 12 ++---------- src/vs/workbench/api/node/extHostDebugService.ts | 13 +++++-------- src/vs/workbench/parts/debug/common/debugUtils.ts | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index adb14a32949..c8c9707804a 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -16,7 +16,6 @@ import severity from 'vs/base/common/severity'; import { AbstractDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { convertToVSCPaths, convertToDAPaths, stringToUri, uriToString } from 'vs/workbench/parts/debug/common/debugUtils'; -import { deepClone } from 'vs/base/common/objects'; @extHostNamedCustomer(MainContext.MainThreadDebugService) export class MainThreadDebugService implements MainThreadDebugServiceShape, IDebugAdapterProvider { @@ -213,9 +212,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb public $acceptDAMessage(handle: number, message: DebugProtocol.ProtocolMessage) { - convertToVSCPaths(message, source => uriToString(source)); - - this._debugAdapters.get(handle).acceptMessage(message); + this._debugAdapters.get(handle).acceptMessage(convertToVSCPaths(message, source => uriToString(source))); } public $acceptDAError(handle: number, name: string, message: string, stack: string) { @@ -293,12 +290,7 @@ class ExtensionHostDebugAdapter extends AbstractDebugAdapter { public sendMessage(message: DebugProtocol.ProtocolMessage): void { - // since we modify Source.paths in the message in place, we need to make a copy of it (see #61129) - const msg = deepClone(message); - - convertToDAPaths(msg, source => stringToUri(source)); - - this._proxy.$sendDAMessage(this._handle, msg); + this._proxy.$sendDAMessage(this._handle, convertToDAPaths(message, source => stringToUri(source))); } public stopSession(): TPromise { diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 2f74d67110a..a7c7ab899cd 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -9,7 +9,6 @@ import { URI, UriComponents } from 'vs/base/common/uri'; import { Event, Emitter } from 'vs/base/common/event'; import { asThenable } from 'vs/base/common/async'; import * as nls from 'vs/nls'; -import { deepClone } from 'vs/base/common/objects'; import { MainContext, MainThreadDebugServiceShape, ExtHostDebugServiceShape, DebugSessionUUID, IMainContext, IBreakpointsDeltaDto, ISourceMultiBreakpointDto, IFunctionBreakpointDto, IDebugSessionDto @@ -391,17 +390,14 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { da.onMessage(message => { - // since we modify Source.paths in the message in place, we need to make a copy of it (see #61129) - const msg = deepClone(message); - if (tracker) { - tracker.fromDebugAdapter(msg); + tracker.fromDebugAdapter(message); } // DA -> VS Code - convertToVSCPaths(msg, source => stringToUri(source)); + message = convertToVSCPaths(message, source => stringToUri(source)); - mythis._debugServiceProxy.$acceptDAMessage(handle, msg); + mythis._debugServiceProxy.$acceptDAMessage(handle, message); }); da.onError(err => { if (tracker) { @@ -429,8 +425,9 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { } public $sendDAMessage(handle: number, message: DebugProtocol.ProtocolMessage): Promise { + // VS Code -> DA - convertToDAPaths(message, source => uriToString(source)); + message = convertToDAPaths(message, source => uriToString(source)); const tracker = this._debugAdaptersTrackers.get(handle); if (tracker) { diff --git a/src/vs/workbench/parts/debug/common/debugUtils.ts b/src/vs/workbench/parts/debug/common/debugUtils.ts index 24091e11889..a12f19a08eb 100644 --- a/src/vs/workbench/parts/debug/common/debugUtils.ts +++ b/src/vs/workbench/parts/debug/common/debugUtils.ts @@ -7,6 +7,7 @@ import { equalsIgnoreCase } from 'vs/base/common/strings'; import { IConfig } from 'vs/workbench/parts/debug/common/debug'; import { URI as uri } from 'vs/base/common/uri'; import { isAbsolute_posix, isAbsolute_win32 } from 'vs/base/common/paths'; +import { deepClone } from 'vs/base/common/objects'; const _formatPIIRegexp = /{([^}]+)}/g; @@ -106,20 +107,30 @@ export function uriToString(source: DebugProtocol.Source): void { // path hooks helpers -export function convertToDAPaths(msg: DebugProtocol.ProtocolMessage, fixSourcePaths: (source: DebugProtocol.Source) => void): void { +export function convertToDAPaths(message: DebugProtocol.ProtocolMessage, fixSourcePaths: (source: DebugProtocol.Source) => void): DebugProtocol.ProtocolMessage { + + // since we modify Source.paths in the message in place, we need to make a copy of it (see #61129) + const msg = deepClone(message); + convertPaths(msg, (toDA: boolean, source: DebugProtocol.Source | undefined) => { if (toDA && source) { fixSourcePaths(source); } }); + return msg; } -export function convertToVSCPaths(msg: DebugProtocol.ProtocolMessage, fixSourcePaths: (source: DebugProtocol.Source) => void): void { +export function convertToVSCPaths(message: DebugProtocol.ProtocolMessage, fixSourcePaths: (source: DebugProtocol.Source) => void): DebugProtocol.ProtocolMessage { + + // since we modify Source.paths in the message in place, we need to make a copy of it (see #61129) + const msg = deepClone(message); + convertPaths(msg, (toDA: boolean, source: DebugProtocol.Source | undefined) => { if (!toDA && source) { fixSourcePaths(source); } }); + return msg; } function convertPaths(msg: DebugProtocol.ProtocolMessage, fixSourcePaths: (toDA: boolean, source: DebugProtocol.Source | undefined) => void): void {