Skip to content

Support opening multi-folder workspaces #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/vscode/src/fill/windowsService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as electron from "electron";
import { createHash } from "crypto";
import { Emitter } from "@coder/events";
import { logger } from "@coder/logger";
import { Schemas } from "vs/base/common/network";
import { originalFSPath } from "vs/base/common/resources";
import { IWindowsService, INativeOpenDialogOptions, MessageBoxOptions, SaveDialogOptions, OpenDialogOptions, IMessageBoxResult, IDevToolsOptions, IEnterWorkspaceResult, CrashReporterStartOptions, INewWindowOptions, IOpenFileRequest, IAddFoldersRequest, IURIToOpen, IOpenSettings } from "vs/platform/windows/common/windows";
import { ParsedArgs } from "vs/platform/environment/common/environment";
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
Expand All @@ -22,6 +25,11 @@ Object.defineProperty(window, "open", {
get: (): Function => windowOpen,
});

const getWorkspaceId = (configPath: URI): string => {
let workspaceConfigPath = configPath.scheme === Schemas.file ? originalFSPath(configPath) : configPath.toString();
return createHash("md5").update(workspaceConfigPath).digest("hex");
};

/**
* Instead of going to the shared process, we'll directly run these methods on
* the client. This setup means we can only control the current window.
Expand Down Expand Up @@ -107,13 +115,11 @@ export class WindowsService implements IWindowsService {
showOpenDialog({
...(options.dialogOptions || {}),
properties: {
openDirectory: true,
openFile: true,
},
}).then((path) => {
// tslint:disable-next-line:no-any
(<any>electron.ipcMain).send("vscode:addFolders", {
foldersToAdd: [URI.file(path)],
} as IAddFoldersRequest);
const configPath = URI.file(path);
workbench.workspace = {id: getWorkspaceId(configPath), configPath};
}).catch((ex) => {
logger.error(ex.message);
});
Expand Down Expand Up @@ -167,7 +173,7 @@ export class WindowsService implements IWindowsService {
public enterWorkspace(_windowId: number, uri: URI): Promise<IEnterWorkspaceResult> {
if (uri.path.endsWith(".json")) {
workbench.workspace = {
id: "Untitled",
id: getWorkspaceId(uri),
configPath: uri,
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class Workbench {
let wid: IWorkspaceIdentifier = (<any>Object).assign({}, workspace);
if (!URI.isUri(wid.configPath)) {
// Ensure that the configPath is a valid URI.
wid.configPath = URI.file(wid.configPath);
wid.configPath = URI.file(wid.configPath.path);
}
config.workspace = wid;
} else {
Expand Down