From cc79edb31220b491c4c97707e00d0b617a26498e Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 13 Feb 2020 12:04:22 -0600 Subject: [PATCH] Fix duplicate files opening with folder parameter Reworked from d574012871e58e503801f869fab5e3d3a4052390 to fit in the new structure. --- scripts/vscode.patch | 40 +++++++++++++++++++++++++++++++++++++ src/node/vscode/server.ts | 42 ++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/scripts/vscode.patch b/scripts/vscode.patch index e13f80cc..77fe4367 100644 --- a/scripts/vscode.patch +++ b/scripts/vscode.patch @@ -211,6 +211,46 @@ index 2c64061da7..c0ef8faedd 100644 } catch (err) { // Do nothing. If we can't read the file we have no // language pack config. +diff --git a/src/vs/code/browser/workbench/workbench.ts b/src/vs/code/browser/workbench/workbench.ts +index a599f5a7eb..ec7ccd43f8 100644 +--- a/src/vs/code/browser/workbench/workbench.ts ++++ b/src/vs/code/browser/workbench/workbench.ts +@@ -298,35 +298,6 @@ class WorkspaceProvider implements IWorkspaceProvider { + let workspace: IWorkspace; + let payload = Object.create(null); + +- const query = new URL(document.location.href).searchParams; +- query.forEach((value, key) => { +- switch (key) { +- +- // Folder +- case WorkspaceProvider.QUERY_PARAM_FOLDER: +- workspace = { folderUri: URI.parse(value) }; +- foundWorkspace = true; +- break; +- +- // Workspace +- case WorkspaceProvider.QUERY_PARAM_WORKSPACE: +- workspace = { workspaceUri: URI.parse(value) }; +- foundWorkspace = true; +- break; +- +- // Empty +- case WorkspaceProvider.QUERY_PARAM_EMPTY_WINDOW: +- workspace = undefined; +- foundWorkspace = true; +- break; +- +- // Payload +- case WorkspaceProvider.QUERY_PARAM_PAYLOAD: +- payload = JSON.parse(value); +- break; +- } +- }); +- + // If no workspace is provided through the URL, check for config attribute from server + if (!foundWorkspace) { + if (config.folderUri) { diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index abd1e33b18..bf75952ce1 100644 --- a/src/vs/platform/environment/common/environment.ts diff --git a/src/node/vscode/server.ts b/src/node/vscode/server.ts index 86eaf8a1..acbf25eb 100644 --- a/src/node/vscode/server.ts +++ b/src/node/vscode/server.ts @@ -167,18 +167,22 @@ export class VscodeHttpProvider extends HttpProvider { } private async getRoot(request: http.IncomingMessage, route: Route): Promise { + const remoteAuthority = request.headers.host as string const settings = await this.settings.read() - const startPath = await this.getFirstValidPath([ - { url: route.query.workspace, workspace: true }, - { url: route.query.folder, workspace: false }, - settings.lastVisited, - this.args._ && this.args._.length > 0 ? { url: this.urlify(this.args._[0]) } : undefined, - ]) + const startPath = await this.getFirstValidPath( + [ + { url: route.query.workspace, workspace: true }, + { url: route.query.folder, workspace: false }, + settings.lastVisited, + this.args._ && this.args._.length > 0 ? { url: this.args._[0] } : undefined, + ], + remoteAuthority + ) const [response, options] = await Promise.all([ await this.getUtf8Resource(this.rootPath, `src/node/vscode/workbench${!this.isDev ? "-build" : ""}.html`), this.initialize({ args: this.args, - remoteAuthority: request.headers.host as string, + remoteAuthority, startPath, }), ]) @@ -217,7 +221,8 @@ export class VscodeHttpProvider extends HttpProvider { * workspace or a directory otherwise. */ private async getFirstValidPath( - startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined> + startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>, + remoteAuthority: string ): Promise { for (let i = 0; i < startPaths.length; ++i) { const startPath = startPaths[i] @@ -226,14 +231,23 @@ export class VscodeHttpProvider extends HttpProvider { } const paths = typeof startPath.url === "string" ? [startPath.url] : startPath.url || [] for (let j = 0; j < paths.length; ++j) { - const u = url.parse(paths[j]) + const uri = url.parse(paths[j]) try { - if (!u.pathname) { + if (!uri.pathname) { throw new Error(`${paths[j]} is not a valid URL`) } - const stat = await fs.stat(u.pathname) + const stat = await fs.stat(uri.pathname) if (typeof startPath.workspace === "undefined" || startPath.workspace !== stat.isDirectory()) { - return { url: u.href, workspace: !stat.isDirectory() } + return { + url: url.format({ + protocol: uri.protocol || "vscode-remote", + hostname: remoteAuthority.split(":")[0], + port: remoteAuthority.split(":")[1], + pathname: uri.pathname, + slashes: true, + }), + workspace: !stat.isDirectory(), + } } } catch (error) { logger.warn(error.message) @@ -242,8 +256,4 @@ export class VscodeHttpProvider extends HttpProvider { } return undefined } - - private urlify(p: string): string { - return "vscode-remote://host" + path.resolve(p) - } }