Skip to content

Commit 139dde2

Browse files
author
Benjamin Pasero
committed
web - change environment to payload API
1 parent 98cd33b commit 139dde2

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/vs/code/browser/workbench/workbench.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ class WorkspaceProvider implements IWorkspaceProvider {
208208

209209
constructor(
210210
public readonly workspace: IWorkspace,
211-
public readonly environment: ReadonlyMap<string, string>
211+
public readonly payload: object
212212
) { }
213213

214-
async open(workspace: IWorkspace, options?: { reuse?: boolean, environment?: Map<string, string> }): Promise<void> {
215-
if (options && options.reuse && !options.environment && this.isSame(this.workspace, workspace)) {
214+
async open(workspace: IWorkspace, options?: { reuse?: boolean, payload?: object }): Promise<void> {
215+
if (options && options.reuse && !options.payload && this.isSame(this.workspace, workspace)) {
216216
return; // return early if workspace and environment is not changing and we are reusing window
217217
}
218218

@@ -233,10 +233,8 @@ class WorkspaceProvider implements IWorkspaceProvider {
233233
}
234234

235235
// Environment
236-
if (options && options.environment) {
237-
for (const [key, value] of options.environment) {
238-
targetHref += `&${key}=${encodeURIComponent(value)}`;
239-
}
236+
if (options && options.payload) {
237+
targetHref += `&payload=${encodeURIComponent(JSON.stringify(options.payload))}`;
240238
}
241239

242240
if (targetHref) {
@@ -290,23 +288,24 @@ class WorkspaceProvider implements IWorkspaceProvider {
290288
workspace = undefined;
291289
}
292290

293-
// Find environmental properties
294-
const environment = new Map<string, string>();
291+
// Find payload
292+
let payload = Object.create(null);
295293
if (document && document.location && document.location.search) {
296294
const query = document.location.search.substring(1);
297295
const vars = query.split('&');
298296
for (let p of vars) {
299297
const pair = p.split('=');
300298
if (pair.length === 2) {
301299
const [key, value] = pair;
302-
if (key !== WorkspaceProvider.QUERY_PARAM_EMPTY_WINDOW && key !== WorkspaceProvider.QUERY_PARAM_FOLDER && key !== WorkspaceProvider.QUERY_PARAM_WORKSPACE) {
303-
environment.set(key, decodeURIComponent(value));
300+
if (key === 'payload') {
301+
payload = JSON.parse(decodeURIComponent(value));
302+
break;
304303
}
305304
}
306305
}
307306
}
308307

309-
options.workspaceProvider = new WorkspaceProvider(workspace, environment);
308+
options.workspaceProvider = new WorkspaceProvider(workspace, payload);
310309
options.urlCallbackProvider = new PollingURLCallbackProvider();
311310
options.credentialsProvider = new LocalStorageCredentialsProvider();
312311

src/vs/workbench/contrib/debug/browser/extensionHostDebugService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService'
1313
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
1414
import { Event } from 'vs/base/common/event';
1515
import { URI } from 'vs/base/common/uri';
16+
import { mapToSerializable } from 'vs/base/common/map';
1617
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1718
import { IWorkspaceProvider, IWorkspace } from 'vs/workbench/services/host/browser/browserHostService';
1819

@@ -64,7 +65,7 @@ class BrowserExtensionHostDebugService extends ExtensionHostDebugChannelClient i
6465
}
6566

6667
async openExtensionDevelopmentHostWindow(args: string[]): Promise<void> {
67-
if (!this.workspaceProvider.environment) {
68+
if (!this.workspaceProvider.payload) {
6869
// TODO@Ben remove me once environment is adopted
6970
return this.openExtensionDevelopmentHostWindowLegacy(args);
7071
}
@@ -96,8 +97,8 @@ class BrowserExtensionHostDebugService extends ExtensionHostDebugChannelClient i
9697

9798
// Open debug window as new window. Pass ParsedArgs over.
9899
this.workspaceProvider.open(debugWorkspace, {
99-
reuse: false, // debugging always requires a new window
100-
environment // mandatory properties to enable debugging
100+
reuse: false, // debugging always requires a new window
101+
payload: mapToSerializable(environment) // mandatory properties to enable debugging
101102
});
102103
}
103104

src/vs/workbench/services/environment/browser/environmentService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platf
1616
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1717
import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api';
1818
import product from 'vs/platform/product/common/product';
19+
import { serializableToMap } from 'vs/base/common/map';
1920

2021
export class BrowserWindowConfiguration implements IWindowConfiguration {
2122

@@ -101,8 +102,8 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
101102
this.untitledWorkspacesHome = URI.from({ scheme: Schemas.untitled, path: 'Workspaces' });
102103

103104
// Fill in selected extra environmental properties
104-
if (options.workspaceProvider && options.workspaceProvider.environment) {
105-
const environment = options.workspaceProvider.environment;
105+
if (options.workspaceProvider && Array.isArray(options.workspaceProvider.payload)) {
106+
const environment = serializableToMap(options.workspaceProvider.payload);
106107
for (const [key, value] of environment) {
107108
switch (key) {
108109
case 'extensionDevelopmentPath':

src/vs/workbench/services/host/browser/browserHostService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ export interface IWorkspaceProvider {
3434
readonly workspace: IWorkspace;
3535

3636
/**
37-
* Optionally a set of environmental properties to be used
38-
* as environment for the workspace to open.
37+
* Arbitrary payload from the `IWorkspaceProvider.open` call.
3938
*/
40-
readonly environment?: ReadonlyMap<string, string>;
39+
readonly payload?: object;
4140

4241
/**
4342
* Asks to open a workspace in the current or a new window.
4443
*
4544
* @param workspace the workspace to open.
4645
* @param options optional options for the workspace to open.
4746
* - `reuse`: wether to open inside the current window or a new window
48-
* - `environment`: a map of environmental properties that should be
49-
* filled into the environment of the workspace to open.
47+
* - `payload`: arbitrary payload that should be made available
48+
* to the opening window via the `IWorkspaceProvider.payload` property.
5049
*/
51-
open(workspace: IWorkspace, options?: { reuse?: boolean, environment?: Map<string, string> }): Promise<void>;
50+
open(workspace: IWorkspace, options?: { reuse?: boolean, payload?: object }): Promise<void>;
5251
}
5352

5453
export class BrowserHostService extends Disposable implements IHostService {

0 commit comments

Comments
 (0)