Skip to content

Commit

Permalink
code --add breaks if executed repeatedly (fixes #38138)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 14, 2017
1 parent 9a91cd0 commit ee85477
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/vs/workbench/electron-browser/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ConfigurationTarget, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { LifecyclePhase, ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';

const TextInputActions: IAction[] = [
new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && TPromise.as(true)),
Expand All @@ -68,6 +69,9 @@ export class ElectronWindow extends Themable {

private previousConfiguredZoomLevel: number;

private addFoldersScheduler: RunOnceScheduler;
private pendingFoldersToAdd: IAddFoldersRequest[];

constructor(
shellContainer: HTMLElement,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
Expand Down Expand Up @@ -96,6 +100,10 @@ export class ElectronWindow extends Themable {
this.touchBarUpdater = new RunOnceScheduler(() => this.doSetupTouchbar(), 300);
this.toUnbind.push(this.touchBarUpdater);

this.pendingFoldersToAdd = [];
this.addFoldersScheduler = new RunOnceScheduler(() => this.doAddFolders(), 100);
this.toUnbind.push(this.addFoldersScheduler);

this.registerListeners();
this.create();
}
Expand Down Expand Up @@ -180,7 +188,7 @@ export class ElectronWindow extends Themable {
ipc.on('vscode:openFiles', (_event: any, request: IOpenFileRequest) => this.onOpenFiles(request));

// Support addFolders event if we have a workspace opened
ipc.on('vscode:addFolders', (_event: any, request: IAddFoldersRequest) => this.onAddFolders(request));
ipc.on('vscode:addFolders', (_event: any, request: IAddFoldersRequest) => this.onAddFoldersRequest(request));

// Message support
ipc.on('vscode:showInfoMessage', (_event: any, message: string) => {
Expand Down Expand Up @@ -394,8 +402,25 @@ export class ElectronWindow extends Themable {
});
}

private onAddFolders(request: IAddFoldersRequest): void {
const foldersToAdd = request.foldersToAdd.map(folderToAdd => ({ uri: URI.file(folderToAdd.filePath) }));
private onAddFoldersRequest(request: IAddFoldersRequest): void {

// Buffer all pending requests
this.pendingFoldersToAdd.push(request);

// Delay the adding of folders a bit to buffer in case more requests are coming
if (!this.addFoldersScheduler.isScheduled()) {
this.addFoldersScheduler.schedule();
}
}

private doAddFolders(): void {
const foldersToAdd: IWorkspaceFolderCreationData[] = [];

this.pendingFoldersToAdd.forEach(request => {
foldersToAdd.push(...request.foldersToAdd.map(folderToAdd => ({ uri: URI.file(folderToAdd.filePath) })));
});

this.pendingFoldersToAdd = [];

this.workspaceEditingService.addFolders(foldersToAdd).done(null, errors.onUnexpectedError);
}
Expand Down

0 comments on commit ee85477

Please sign in to comment.