Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc79edb

Browse files
committedFeb 13, 2020
Fix duplicate files opening with folder parameter
Reworked from d574012 to fit in the new structure.
1 parent ac4f2b8 commit cc79edb

File tree

2 files changed

+66
-16
lines changed

2 files changed

+66
-16
lines changed
 

‎scripts/vscode.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,46 @@ index 2c64061da7..c0ef8faedd 100644
211211
} catch (err) {
212212
// Do nothing. If we can't read the file we have no
213213
// language pack config.
214+
diff --git a/src/vs/code/browser/workbench/workbench.ts b/src/vs/code/browser/workbench/workbench.ts
215+
index a599f5a7eb..ec7ccd43f8 100644
216+
--- a/src/vs/code/browser/workbench/workbench.ts
217+
+++ b/src/vs/code/browser/workbench/workbench.ts
218+
@@ -298,35 +298,6 @@ class WorkspaceProvider implements IWorkspaceProvider {
219+
let workspace: IWorkspace;
220+
let payload = Object.create(null);
221+
222+
- const query = new URL(document.location.href).searchParams;
223+
- query.forEach((value, key) => {
224+
- switch (key) {
225+
-
226+
- // Folder
227+
- case WorkspaceProvider.QUERY_PARAM_FOLDER:
228+
- workspace = { folderUri: URI.parse(value) };
229+
- foundWorkspace = true;
230+
- break;
231+
-
232+
- // Workspace
233+
- case WorkspaceProvider.QUERY_PARAM_WORKSPACE:
234+
- workspace = { workspaceUri: URI.parse(value) };
235+
- foundWorkspace = true;
236+
- break;
237+
-
238+
- // Empty
239+
- case WorkspaceProvider.QUERY_PARAM_EMPTY_WINDOW:
240+
- workspace = undefined;
241+
- foundWorkspace = true;
242+
- break;
243+
-
244+
- // Payload
245+
- case WorkspaceProvider.QUERY_PARAM_PAYLOAD:
246+
- payload = JSON.parse(value);
247+
- break;
248+
- }
249+
- });
250+
-
251+
// If no workspace is provided through the URL, check for config attribute from server
252+
if (!foundWorkspace) {
253+
if (config.folderUri) {
214254
diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts
215255
index abd1e33b18..bf75952ce1 100644
216256
--- a/src/vs/platform/environment/common/environment.ts

‎src/node/vscode/server.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,22 @@ export class VscodeHttpProvider extends HttpProvider {
167167
}
168168

169169
private async getRoot(request: http.IncomingMessage, route: Route): Promise<HttpResponse> {
170+
const remoteAuthority = request.headers.host as string
170171
const settings = await this.settings.read()
171-
const startPath = await this.getFirstValidPath([
172-
{ url: route.query.workspace, workspace: true },
173-
{ url: route.query.folder, workspace: false },
174-
settings.lastVisited,
175-
this.args._ && this.args._.length > 0 ? { url: this.urlify(this.args._[0]) } : undefined,
176-
])
172+
const startPath = await this.getFirstValidPath(
173+
[
174+
{ url: route.query.workspace, workspace: true },
175+
{ url: route.query.folder, workspace: false },
176+
settings.lastVisited,
177+
this.args._ && this.args._.length > 0 ? { url: this.args._[0] } : undefined,
178+
],
179+
remoteAuthority
180+
)
177181
const [response, options] = await Promise.all([
178182
await this.getUtf8Resource(this.rootPath, `src/node/vscode/workbench${!this.isDev ? "-build" : ""}.html`),
179183
this.initialize({
180184
args: this.args,
181-
remoteAuthority: request.headers.host as string,
185+
remoteAuthority,
182186
startPath,
183187
}),
184188
])
@@ -217,7 +221,8 @@ export class VscodeHttpProvider extends HttpProvider {
217221
* workspace or a directory otherwise.
218222
*/
219223
private async getFirstValidPath(
220-
startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>
224+
startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>,
225+
remoteAuthority: string
221226
): Promise<StartPath | undefined> {
222227
for (let i = 0; i < startPaths.length; ++i) {
223228
const startPath = startPaths[i]
@@ -226,14 +231,23 @@ export class VscodeHttpProvider extends HttpProvider {
226231
}
227232
const paths = typeof startPath.url === "string" ? [startPath.url] : startPath.url || []
228233
for (let j = 0; j < paths.length; ++j) {
229-
const u = url.parse(paths[j])
234+
const uri = url.parse(paths[j])
230235
try {
231-
if (!u.pathname) {
236+
if (!uri.pathname) {
232237
throw new Error(`${paths[j]} is not a valid URL`)
233238
}
234-
const stat = await fs.stat(u.pathname)
239+
const stat = await fs.stat(uri.pathname)
235240
if (typeof startPath.workspace === "undefined" || startPath.workspace !== stat.isDirectory()) {
236-
return { url: u.href, workspace: !stat.isDirectory() }
241+
return {
242+
url: url.format({
243+
protocol: uri.protocol || "vscode-remote",
244+
hostname: remoteAuthority.split(":")[0],
245+
port: remoteAuthority.split(":")[1],
246+
pathname: uri.pathname,
247+
slashes: true,
248+
}),
249+
workspace: !stat.isDirectory(),
250+
}
237251
}
238252
} catch (error) {
239253
logger.warn(error.message)
@@ -242,8 +256,4 @@ export class VscodeHttpProvider extends HttpProvider {
242256
}
243257
return undefined
244258
}
245-
246-
private urlify(p: string): string {
247-
return "vscode-remote://host" + path.resolve(p)
248-
}
249259
}

0 commit comments

Comments
 (0)
Please sign in to comment.