Skip to content

Commit

Permalink
fix the workspace pref not being applied on change
Browse files Browse the repository at this point in the history
- FolderPreferenceProvider should be associated with PreferenceScope.Workspace when it is used as a delegate of WorkspacePreferenceProvider in a one-folder workspace, otherwise changes made to the workspace preferences would not be applied to the IDE.
- fixed #5446

Signed-off-by: elaihau <liang.huang@ericsson.com>
  • Loading branch information
elaihau committed Jun 26, 2019
1 parent f2e4f2c commit a45bbcb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
11 changes: 10 additions & 1 deletion packages/core/src/browser/preferences/preference-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,16 @@ export class PreferenceServiceImpl implements PreferenceService, FrontendApplica
if (scope > change.scope && value !== undefined) {
// preference defined in a more specific scope
break;
} else if (scope === change.scope) {
} else if (scope === change.scope && change.newValue !== undefined) {
// preference is changed into something other than `undefined`
acceptChange(change);
} else if (scope < change.scope && change.newValue === undefined && value !== undefined) {
// preference is changed to `undefined`, use the value from a more general scope
change = {
...change,
newValue: value,
scope
};
acceptChange(change);
}
}
Expand Down
10 changes: 3 additions & 7 deletions packages/preferences/src/browser/folder-preference-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ export interface FolderPreferenceProviderOptions {
@injectable()
export class FolderPreferenceProvider extends AbstractResourcePreferenceProvider {

readonly folderUri: URI;

@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
@inject(FolderPreferenceProviderOptions) protected readonly options: FolderPreferenceProviderOptions;

constructor(
@inject(FolderPreferenceProviderOptions) protected readonly options: FolderPreferenceProviderOptions,
) {
super();
this.folderUri = new URI(this.options.folder.uri);
get folderUri(): URI {
return new URI(this.options.folder.uri);
}

protected getUri(): URI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class FoldersPreferencesProvider extends PreferenceProvider {

this.updateProviders();
this.workspaceService.onWorkspaceChanged(() => this.updateProviders());

const readyPromises: Promise<void>[] = [];
for (const provider of this.providers.values()) {
readyPromises.push(provider.ready.catch(e => console.error(e)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class WorkspacePreferenceProvider extends PreferenceProvider {

protected ensureResourceUri(): string | undefined {
if (this.workspaceService.workspace && !this.workspaceService.isMultiRootWorkspaceOpened) {
return this.workspaceService.workspace!.uri;
return this.workspaceService.workspace.uri;
}
return undefined;
}
Expand Down

0 comments on commit a45bbcb

Please sign in to comment.