Skip to content

Commit 6f03367

Browse files
committed
microsoft#35996 Use getValue in ResourceConfigurationService
1 parent e4af77b commit 6f03367

19 files changed

Lines changed: 82 additions & 55 deletions

File tree

src/vs/editor/common/services/editorWorkerServiceImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class WordBasedCompletionItemProvider implements modes.ISuggestSupport {
125125
}
126126

127127
provideCompletionItems(model: editorCommon.IModel, position: Position): TPromise<modes.ISuggestResult> {
128-
const { wordBasedSuggestions } = this._configurationService.getConfiguration<IEditorOptions>(model.uri, position, 'editor');
128+
const { wordBasedSuggestions } = this._configurationService.getValue<IEditorOptions>(model.uri, position, 'editor');
129129
if (!wordBasedSuggestions) {
130130
return undefined;
131131
}

src/vs/editor/common/services/resourceConfiguration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export interface ITextResourceConfigurationService {
2121
onDidChangeConfiguration: Event<IConfigurationChangeEvent>;
2222

2323
/**
24-
* Fetches the appropriate section of the for the given resource with appropriate overrides (e.g. language).
25-
* This will be an object keyed off the section name.
24+
* Fetches the value of the section for the given resource by applying language overrides.
25+
* Value can be of native type or an object keyed off the section name.
2626
*
2727
* @param resource - Resource for which the configuration has to be fetched. Can be `null` or `undefined`.
2828
* @param postion - Position in the resource for which configuration has to be fetched. Can be `null` or `undefined`.
2929
* @param section - Section of the configuraion. Can be `null` or `undefined`.
3030
*
3131
*/
32-
getConfiguration<T>(resource: URI, section?: string): T;
33-
getConfiguration<T>(resource: URI, position?: IPosition, section?: string): T;
32+
getValue<T>(resource: URI, section?: string): T;
33+
getValue<T>(resource: URI, position?: IPosition, section?: string): T;
3434

3535
}

src/vs/editor/common/services/resourceConfigurationImpl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export class TextResourceConfigurationService extends Disposable implements ITex
2828
this._register(this.configurationService.onDidChangeConfiguration(e => this._onDidChangeConfiguration.fire(e)));
2929
}
3030

31-
getConfiguration<T>(resource: URI, section?: string): T;
32-
getConfiguration<T>(resource: URI, at?: IPosition, section?: string): T;
33-
getConfiguration<T>(resource: URI, arg2?: any, arg3?: any): T {
31+
getValue<T>(resource: URI, section?: string): T;
32+
getValue<T>(resource: URI, at?: IPosition, section?: string): T;
33+
getValue<T>(resource: URI, arg2?: any, arg3?: any): T {
3434
const position: IPosition = Position.isIPosition(arg2) ? arg2 : null;
3535
const section: string = position ? (typeof arg3 === 'string' ? arg3 : void 0) : (typeof arg2 === 'string' ? arg2 : void 0);
3636
const language = resource ? this.getLanguage(resource, position) : void 0;
37-
return this.configurationService.getConfiguration<T>(section, { resource, overrideIdentifier: language });
37+
return this.configurationService.getValue<T>(section, { resource, overrideIdentifier: language });
3838
}
3939

4040
private getLanguage(resource: URI, position: IPosition): string {

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,14 @@ export class SimpleConfigurationService implements IConfigurationService {
468468
return this.configuration().getSection(section, overrides, null);
469469
}
470470

471-
public getValue<C>(key: string, options: IConfigurationOverrides = {}): C {
472-
return this.configuration().getValue(key, options, null);
471+
getValue<T>(): T;
472+
getValue<T>(section: string): T;
473+
getValue<T>(overrides: IConfigurationOverrides): T;
474+
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
475+
getValue(arg1?: any, arg2?: any): any {
476+
const section = typeof arg1 === 'string' ? arg1 : void 0;
477+
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
478+
return this.configuration().getValue(section, overrides, null);
473479
}
474480

475481
public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> {
@@ -512,8 +518,8 @@ export class SimpleResourceConfigurationService implements ITextResourceConfigur
512518
});
513519
}
514520

515-
public getConfiguration<T>(): T {
516-
return this.configurationService.getConfiguration<T>();
521+
public getValue<T>(): T {
522+
return this.configurationService.getValue<T>();
517523
}
518524

519525
}

src/vs/platform/configuration/common/configuration.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ export interface IConfigurationService {
6262
getConfiguration<T>(overrides: IConfigurationOverrides): T;
6363
getConfiguration<T>(section: string, overrides: IConfigurationOverrides): T;
6464

65-
getValue<T>(key: string, overrides?: IConfigurationOverrides): T;
65+
/**
66+
* Fetches the value of the section for the given overrides.
67+
* Value can be of native type or an object keyed off the section name.
68+
*
69+
* @param section - Section of the configuraion. Can be `null` or `undefined`.
70+
* @param overrides - Overrides that has to be applied while fetching
71+
*
72+
*/
73+
getValue<T>(): T;
74+
getValue<T>(section: string): T;
75+
getValue<T>(overrides: IConfigurationOverrides): T;
76+
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
6677

6778
updateValue(key: string, value: any): TPromise<void>;
6879
updateValue(key: string, value: any, overrides: IConfigurationOverrides): TPromise<void>;

src/vs/platform/configuration/common/configurationModels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ export class Configuration {
303303
return section ? configModel.getSectionContents<C>(section) : configModel.contents;
304304
}
305305

306-
getValue(key: string, overrides: IConfigurationOverrides, workspace: Workspace): any {
306+
getValue(section: string, overrides: IConfigurationOverrides, workspace: Workspace): any {
307307
const consolidateConfigurationModel = this.getConsolidateConfigurationModel(overrides, workspace);
308-
return getConfigurationValue<any>(consolidateConfigurationModel.contents, key);
308+
return section ? getConfigurationValue<any>(consolidateConfigurationModel.contents, section) : consolidateConfigurationModel.contents;
309309
}
310310

311311
updateValue(key: string, value: any, overrides: IConfigurationOverrides = {}): void {

src/vs/platform/configuration/node/configurationService.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
5858
return this.configuration.getSection(section, overrides, null);
5959
}
6060

61-
getValue(key: string, overrides: IConfigurationOverrides = {}): any {
62-
return this.configuration.getValue(key, overrides, null);
61+
getValue<T>(): T;
62+
getValue<T>(section: string): T;
63+
getValue<T>(overrides: IConfigurationOverrides): T;
64+
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
65+
getValue(arg1?: any, arg2?: any): any {
66+
const section = typeof arg1 === 'string' ? arg1 : void 0;
67+
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
68+
return this.configuration.getValue(section, overrides, null);
6369
}
6470

6571
updateValue(key: string, value: any): TPromise<void>;

src/vs/platform/configuration/test/common/testConfigurationService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ export class TestConfigurationService extends EventEmitter implements IConfigura
3232
return this.configuration;
3333
}
3434

35-
public getValue(key: string, overrides?: IConfigurationOverrides): any {
36-
return this.inspect(key).value;
35+
public getValue(arg1?: any, arg2?: any): any {
36+
if (arg1 && typeof arg1 === 'string') {
37+
return this.inspect(<string>arg1).value;
38+
}
39+
return this.getConfiguration(arg1, arg2);
3740
}
3841

3942
public updateValue(key: string, overrides?: IConfigurationOverrides): TPromise<void> {

src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,10 @@ suite('TelemetryService', () => {
681681
enableTelemetry: enableTelemetry
682682
} as any;
683683
},
684-
getValue(key) {
685-
return getConfigurationValue(this.getConfiguration(), key);
684+
getValue() {
685+
return {
686+
enableTelemetry: enableTelemetry
687+
} as any;
686688
},
687689
updateValue(): TPromise<void> {
688690
return null;

src/vs/workbench/browser/parts/editor/editorStatus.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/
3333
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
3434
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
3535
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
36-
import { SUPPORTED_ENCODINGS, IFileService, IFilesConfiguration, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
36+
import { SUPPORTED_ENCODINGS, IFileService, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
3737
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3838
import { IModeService } from 'vs/editor/common/services/modeService';
3939
import { IModelService } from 'vs/editor/common/services/modelService';
@@ -1159,8 +1159,7 @@ export class ChangeEncodingAction extends Action {
11591159
.then((guessedEncoding: string) => {
11601160
const isReopenWithEncoding = (action === reopenWithEncodingPick);
11611161

1162-
const config = this.textResourceConfigurationService.getConfiguration(resource) as IFilesConfiguration;
1163-
const configuredEncoding = config && config.files && config.files.encoding;
1162+
const configuredEncoding = this.textResourceConfigurationService.getValue(resource, 'files.encoding');
11641163

11651164
let directMatchIndex: number;
11661165
let aliasMatchIndex: number;

0 commit comments

Comments
 (0)