Skip to content

Commit

Permalink
Change default scope for PreferenceService.set
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
  • Loading branch information
colin-grant-work committed Mar 10, 2021
1 parent bb17f71 commit 1b94533
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/browser/preferences/preference-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export interface PreferenceService extends Disposable {
* @param value the new value of the preference.
* @param scope the scope for which the value shall be set, i.e. user, workspace etc.
* When the folder scope is specified a resourceUri must be provided.
* Defaults to folder scope if resourceUri is provided, user scope otherwise.
* @param resourceUri the uri of the resource for which the preference is stored. This used to store
* a potentially different value for the same preference for different resources, for example `files.encoding`.
*
Expand Down Expand Up @@ -401,9 +402,9 @@ export class PreferenceServiceImpl implements PreferenceService {
}

async set(preferenceName: string, value: any, scope: PreferenceScope | undefined, resourceUri?: string): Promise<void> {
const resolvedScope = scope !== undefined ? scope : (!resourceUri ? PreferenceScope.Workspace : PreferenceScope.Folder);
if (resolvedScope === PreferenceScope.User && this.configurations.isSectionName(preferenceName.split('.', 1)[0])) {
throw new Error(`Unable to write to User Settings because ${preferenceName} does not support for global scope.`);
const resolvedScope = scope ?? (resourceUri ? PreferenceScope.Folder : PreferenceScope.User);
if (!this.schema.isValidInScope(preferenceName, resolvedScope)) {
throw new Error(`Unable to write to ${PreferenceScope[resolvedScope]} scope because ${preferenceName} is not supported in that scope.`);
}
if (resolvedScope === PreferenceScope.Folder && !resourceUri) {
throw new Error('Unable to write to Folder Settings because no resource is provided.');
Expand Down

0 comments on commit 1b94533

Please sign in to comment.