Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Feb 14, 2018
1 parent 2851180 commit 00262fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/vs/workbench/services/configuration/node/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ export class WorkspaceConfiguration extends Disposable {

this._workspaceConfigPath = workspaceConfigPath;

this.stopListeningToWatcher();
return new TPromise<void>((c, e) => {
const defaultConfig = new WorkspaceConfigurationModelParser(this._workspaceConfigPath.fsPath);
defaultConfig.parse(JSON.stringify({ folders: [] } as IStoredWorkspace, null, '\t'));
if (this._workspaceConfigurationWatcher) {
this.stopListeningToWatcher();
this._workspaceConfigurationWatcher.dispose();
}
this._workspaceConfigurationWatcher = new ConfigWatcher(this._workspaceConfigPath.fsPath, {
changeBufferDelay: 300,
onError: error => errors.onUnexpectedError(error),
Expand Down Expand Up @@ -144,7 +147,6 @@ export class WorkspaceConfiguration extends Disposable {
}

private listenToWatcher() {
this._workspaceConfigurationWatcherDisposables.push(this._workspaceConfigurationWatcher);
this._workspaceConfigurationWatcher.onDidUpdateConfiguration(() => this._onDidUpdateConfiguration.fire(), this, this._workspaceConfigurationWatcherDisposables);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ suite('WorkspaceContextService - Workspace', () => {
});
});

test('remove folders and add them back by writing into the file', done => {
const folders = testObject.getWorkspace().folders;
return testObject.removeFolders([folders[0].uri])
.then(() => {
testObject.onDidChangeWorkspaceFolders(actual => {
assert.deepEqual(actual.added.map(r => r.uri.toString()), [folders[0].uri.toString()]);
done();
});
const workspace = { folders: [{ path: folders[0].uri.fsPath }, { path: folders[1].uri.fsPath }] };
fs.writeFileSync(testObject.getWorkspace().configuration.fsPath, JSON.stringify(workspace, null, '\t'));
});
});

test('update folders (remove last and add to end)', () => {
const target = sinon.spy();
testObject.onDidChangeWorkspaceFolders(target);
Expand Down

0 comments on commit 00262fb

Please sign in to comment.