Skip to content

Commit 6737384

Browse files
committed
Handle existing query when opening folder
1 parent f61a0ae commit 6737384

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

scripts/vscode.patch

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,20 +583,21 @@ index ede771a03e..bb40fcdd6b 100644
583583
if (!userDataProvider) {
584584
const remoteUserDataUri = this.getRemoteUserDataUri();
585585
diff --git a/src/vs/workbench/browser/web.simpleservices.ts b/src/vs/workbench/browser/web.simpleservices.ts
586-
index 25414d8733..a0de828393 100644
586+
index 25414d8733..20b0ad4a49 100644
587587
--- a/src/vs/workbench/browser/web.simpleservices.ts
588588
+++ b/src/vs/workbench/browser/web.simpleservices.ts
589-
@@ -38,6 +38,9 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
589+
@@ -38,6 +38,10 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
590590
import { IExperimentService, IExperiment, ExperimentActionType, ExperimentState } from 'vs/workbench/contrib/experiments/common/experimentService';
591591
import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc';
592592
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
593593
+import { ExtensionManagementChannelClient } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
594+
+import { withQuery } from 'vs/server/src/client';
594595
+import { IUploadService, UploadService } from 'vs/server/src/upload';
595596
+registerSingleton(IUploadService, UploadService, true);
596597

597598
//#region Extension Tips
598599

599-
@@ -131,7 +134,15 @@ export class SimpleExtensionManagementService implements IExtensionManagementSer
600+
@@ -131,7 +135,15 @@ export class SimpleExtensionManagementService implements IExtensionManagementSer
600601
}
601602
}
602603

@@ -613,7 +614,7 @@ index 25414d8733..a0de828393 100644
613614

614615
//#endregion
615616

616-
@@ -251,7 +262,7 @@ export class SimpleUpdateService implements IUpdateService {
617+
@@ -251,7 +263,7 @@ export class SimpleUpdateService implements IUpdateService {
617618
}
618619
}
619620

@@ -622,25 +623,32 @@ index 25414d8733..a0de828393 100644
622623

623624
//#endregion
624625

625-
@@ -491,7 +502,7 @@ export class SimpleWindowService extends Disposable implements IWindowService {
626+
@@ -491,7 +503,11 @@ export class SimpleWindowService extends Disposable implements IWindowService {
626627
for (let i = 0; i < _uris.length; i++) {
627628
const uri = _uris[i];
628629
if ('folderUri' in uri) {
629630
- const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}${this.workbenchEnvironmentService.configuration.connectionToken ? `&tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
630-
+ const newAddress = `${window.location}?folder=${uri.folderUri.path}${this.workbenchEnvironmentService.configuration.connectionToken ? `&tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
631+
+ const newAddress = withQuery(window.location.toString(), {
632+
+ folder: uri.folderUri.path,
633+
+ tkn: this.workbenchEnvironmentService.configuration.connectionToken,
634+
+ workspace: undefined,
635+
+ });
631636
if (openFolderInNewWindow) {
632637
window.open(newAddress);
633638
} else {
634-
@@ -499,7 +510,7 @@ export class SimpleWindowService extends Disposable implements IWindowService {
639+
@@ -499,7 +515,10 @@ export class SimpleWindowService extends Disposable implements IWindowService {
635640
}
636641
}
637642
if ('workspaceUri' in uri) {
638643
- const newAddress = `${document.location.origin}/?workspace=${uri.workspaceUri.path}`;
639-
+ const newAddress = `${window.location}?workspace=${uri.workspaceUri.path}`;
644+
+ const newAddress = withQuery(window.location.toString(), {
645+
+ folder: undefined,
646+
+ workspace: uri.workspaceUri.path,
647+
+ });
640648
if (openFolderInNewWindow) {
641649
window.open(newAddress);
642650
} else {
643-
@@ -718,6 +729,7 @@ export class SimpleWindowsService implements IWindowsService {
651+
@@ -718,6 +737,7 @@ export class SimpleWindowsService implements IWindowsService {
644652
}
645653

646654
relaunch(_options: { addArgs?: string[], removeArgs?: string[] }): Promise<void> {

src/client.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { URI } from "vs/base/common/uri";
12
import { registerSingleton } from "vs/platform/instantiation/common/extensions";
23
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
34
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
@@ -39,3 +40,28 @@ export const initialize = async (services: ServiceCollection): Promise<void> =>
3940
(event as any).vscode = target.vscode;
4041
window.dispatchEvent(event);
4142
};
43+
44+
export interface Query {
45+
[key: string]: string | undefined;
46+
}
47+
48+
/**
49+
* Return the URL modified with the specified query variables. It's pretty
50+
* stupid so it probably doesn't cover any edge cases. Undefined values will
51+
* unset existing values. Doesn't allow duplicates.
52+
*/
53+
export const withQuery = (url: string, replace: Query): string => {
54+
const uri = URI.parse(url);
55+
const query = { ...replace };
56+
uri.query.split("&").forEach((kv) => {
57+
const [key, value] = kv.split("=", 2);
58+
if (!(key in query)) {
59+
query[key] = value;
60+
}
61+
});
62+
return uri.with({
63+
query: Object.keys(query)
64+
.filter((k) => typeof query[k] !== "undefined")
65+
.map((k) => `${k}=${query[k]}`).join("&"),
66+
}).toString(true);
67+
};

0 commit comments

Comments
 (0)