config service: emit event if config changes after calling reloadConfiguration()
This commit is contained in:
parent
5ee27bcdcb
commit
19bf8e0f42
|
@ -125,13 +125,23 @@ export class WorkspaceConfigurationService implements IWorkspaceConfigurationSer
|
|||
}
|
||||
|
||||
public reloadConfiguration(section?: string): TPromise<any> {
|
||||
const previousConfig = this.getConfiguration();
|
||||
|
||||
// Reset caches to ensure we are hitting the disk
|
||||
this.bulkFetchFromWorkspacePromise = null;
|
||||
this.workspaceFilePathToConfiguration = Object.create(null);
|
||||
|
||||
// Load configuration
|
||||
return this.baseConfigurationService.reloadConfiguration().then(() => this.doLoadConfiguration(section));
|
||||
return this.baseConfigurationService.reloadConfiguration().then(() => this.doLoadConfiguration(section).then(res => {
|
||||
|
||||
// Since we reload the configuration, we also check for changes and emit an event in case the config changed
|
||||
const currentConfig = this.getConfiguration();
|
||||
if (!objects.equals(previousConfig, currentConfig)) {
|
||||
this._onDidUpdateConfiguration.fire({ config: currentConfig });
|
||||
}
|
||||
|
||||
return res;
|
||||
}));
|
||||
}
|
||||
|
||||
private doLoadConfiguration(section?: string): TPromise<any> {
|
||||
|
|
|
@ -108,6 +108,31 @@ suite('WorkspaceConfigurationService - Node', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('reload configuration emits events', (done: () => void) => {
|
||||
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
|
||||
return createService(workspaceDir, globalSettingsFile).then(service => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "testworkbench.editor.tabs": true }');
|
||||
|
||||
return service.initialize().then(() => {
|
||||
service.onDidUpdateConfiguration(event => {
|
||||
const config = service.getConfiguration<{ testworkbench: { editor: { tabs: boolean } } }>();
|
||||
assert.equal(config.testworkbench.editor.tabs, false);
|
||||
|
||||
service.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
});
|
||||
|
||||
fs.writeFileSync(globalSettingsFile, '{ "testworkbench.editor.tabs": false }');
|
||||
|
||||
// this has to trigger the event since the config changes
|
||||
service.reloadConfiguration().done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('globals override defaults', (done: () => void) => {
|
||||
interface ITestSetting {
|
||||
workspace: {
|
||||
|
|
Loading…
Reference in a new issue