Fix duplicate files opening with folder parameter
Reworked from d574012871
to fit in the
new structure.
This commit is contained in:
parent
ac4f2b8215
commit
cc79edb312
|
@ -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
|
||||
|
|
|
@ -167,18 +167,22 @@ export class VscodeHttpProvider extends HttpProvider {
|
|||
}
|
||||
|
||||
private async getRoot(request: http.IncomingMessage, route: Route): Promise<HttpResponse> {
|
||||
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<StartPath | undefined> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue