Skip to content

Commit

Permalink
#35996 Use getValue in ResourceConfigurationService
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Nov 10, 2017
1 parent e4af77b commit 6f03367
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/common/services/editorWorkerServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class WordBasedCompletionItemProvider implements modes.ISuggestSupport {
}

provideCompletionItems(model: editorCommon.IModel, position: Position): TPromise<modes.ISuggestResult> {
const { wordBasedSuggestions } = this._configurationService.getConfiguration<IEditorOptions>(model.uri, position, 'editor');
const { wordBasedSuggestions } = this._configurationService.getValue<IEditorOptions>(model.uri, position, 'editor');
if (!wordBasedSuggestions) {
return undefined;
}
Expand Down
8 changes: 4 additions & 4 deletions src/vs/editor/common/services/resourceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export interface ITextResourceConfigurationService {
onDidChangeConfiguration: Event<IConfigurationChangeEvent>;

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

}
8 changes: 4 additions & 4 deletions src/vs/editor/common/services/resourceConfigurationImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export class TextResourceConfigurationService extends Disposable implements ITex
this._register(this.configurationService.onDidChangeConfiguration(e => this._onDidChangeConfiguration.fire(e)));
}

getConfiguration<T>(resource: URI, section?: string): T;
getConfiguration<T>(resource: URI, at?: IPosition, section?: string): T;
getConfiguration<T>(resource: URI, arg2?: any, arg3?: any): T {
getValue<T>(resource: URI, section?: string): T;
getValue<T>(resource: URI, at?: IPosition, section?: string): T;
getValue<T>(resource: URI, arg2?: any, arg3?: any): T {
const position: IPosition = Position.isIPosition(arg2) ? arg2 : null;
const section: string = position ? (typeof arg3 === 'string' ? arg3 : void 0) : (typeof arg2 === 'string' ? arg2 : void 0);
const language = resource ? this.getLanguage(resource, position) : void 0;
return this.configurationService.getConfiguration<T>(section, { resource, overrideIdentifier: language });
return this.configurationService.getValue<T>(section, { resource, overrideIdentifier: language });
}

private getLanguage(resource: URI, position: IPosition): string {
Expand Down
14 changes: 10 additions & 4 deletions src/vs/editor/standalone/browser/simpleServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,14 @@ export class SimpleConfigurationService implements IConfigurationService {
return this.configuration().getSection(section, overrides, null);
}

public getValue<C>(key: string, options: IConfigurationOverrides = {}): C {
return this.configuration().getValue(key, options, null);
getValue<T>(): T;
getValue<T>(section: string): T;
getValue<T>(overrides: IConfigurationOverrides): T;
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
getValue(arg1?: any, arg2?: any): any {
const section = typeof arg1 === 'string' ? arg1 : void 0;
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
return this.configuration().getValue(section, overrides, null);
}

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

public getConfiguration<T>(): T {
return this.configurationService.getConfiguration<T>();
public getValue<T>(): T {
return this.configurationService.getValue<T>();
}

}
Expand Down
13 changes: 12 additions & 1 deletion src/vs/platform/configuration/common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ export interface IConfigurationService {
getConfiguration<T>(overrides: IConfigurationOverrides): T;
getConfiguration<T>(section: string, overrides: IConfigurationOverrides): T;

getValue<T>(key: string, overrides?: IConfigurationOverrides): T;
/**
* Fetches the value of the section for the given overrides.
* Value can be of native type or an object keyed off the section name.
*
* @param section - Section of the configuraion. Can be `null` or `undefined`.
* @param overrides - Overrides that has to be applied while fetching
*
*/
getValue<T>(): T;
getValue<T>(section: string): T;
getValue<T>(overrides: IConfigurationOverrides): T;
getValue<T>(section: string, overrides: IConfigurationOverrides): T;

updateValue(key: string, value: any): TPromise<void>;
updateValue(key: string, value: any, overrides: IConfigurationOverrides): TPromise<void>;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/configuration/common/configurationModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ export class Configuration {
return section ? configModel.getSectionContents<C>(section) : configModel.contents;
}

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

updateValue(key: string, value: any, overrides: IConfigurationOverrides = {}): void {
Expand Down
10 changes: 8 additions & 2 deletions src/vs/platform/configuration/node/configurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
return this.configuration.getSection(section, overrides, null);
}

getValue(key: string, overrides: IConfigurationOverrides = {}): any {
return this.configuration.getValue(key, overrides, null);
getValue<T>(): T;
getValue<T>(section: string): T;
getValue<T>(overrides: IConfigurationOverrides): T;
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
getValue(arg1?: any, arg2?: any): any {
const section = typeof arg1 === 'string' ? arg1 : void 0;
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
return this.configuration.getValue(section, overrides, null);
}

updateValue(key: string, value: any): TPromise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export class TestConfigurationService extends EventEmitter implements IConfigura
return this.configuration;
}

public getValue(key: string, overrides?: IConfigurationOverrides): any {
return this.inspect(key).value;
public getValue(arg1?: any, arg2?: any): any {
if (arg1 && typeof arg1 === 'string') {
return this.inspect(<string>arg1).value;
}
return this.getConfiguration(arg1, arg2);
}

public updateValue(key: string, overrides?: IConfigurationOverrides): TPromise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,10 @@ suite('TelemetryService', () => {
enableTelemetry: enableTelemetry
} as any;
},
getValue(key) {
return getConfigurationValue(this.getConfiguration(), key);
getValue() {
return {
enableTelemetry: enableTelemetry
} as any;
},
updateValue(): TPromise<void> {
return null;
Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/browser/parts/editor/editorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { SUPPORTED_ENCODINGS, IFileService, IFilesConfiguration, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
import { SUPPORTED_ENCODINGS, IFileService, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';
Expand Down Expand Up @@ -1159,8 +1159,7 @@ export class ChangeEncodingAction extends Action {
.then((guessedEncoding: string) => {
const isReopenWithEncoding = (action === reopenWithEncodingPick);

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

let directMatchIndex: number;
let aliasMatchIndex: number;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/editor/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class BaseTextEditor extends BaseEditor {
) {
super(id, telemetryService, themeService);

this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.handleConfigurationChangeEvent(this.configurationService.getConfiguration<IEditorConfiguration>(this.getResource()))));
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.handleConfigurationChangeEvent(this.configurationService.getValue<IEditorConfiguration>(this.getResource()))));
}

protected get instantiationService(): IInstantiationService {
Expand Down Expand Up @@ -127,7 +127,7 @@ export abstract class BaseTextEditor extends BaseEditor {

// Editor for Text
this._editorContainer = parent;
this.editorControl = this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getConfiguration<IEditorConfiguration>(this.getResource())));
this.editorControl = this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getValue<IEditorConfiguration>(this.getResource())));

// Model & Language changes
const codeEditor = getCodeEditor(this);
Expand Down Expand Up @@ -280,7 +280,7 @@ export abstract class BaseTextEditor extends BaseEditor {
return null;
}

private updateEditorConfiguration(configuration = this.configurationService.getConfiguration<IEditorConfiguration>(this.getResource())): void {
private updateEditorConfiguration(configuration = this.configurationService.getValue<IEditorConfiguration>(this.getResource())): void {
if (!this.editorControl) {
return;
}
Expand Down
9 changes: 3 additions & 6 deletions src/vs/workbench/common/editor/untitledEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'
import URI from 'vs/base/common/uri';
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { EndOfLinePreference } from 'vs/editor/common/editorCommon';
import { IFilesConfiguration, CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
import { CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IMode } from 'vs/editor/common/modes';
Expand Down Expand Up @@ -98,8 +98,7 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
}

private onConfigurationChange(): void {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>(this.resource);
const configuredEncoding = configuration && configuration.files && configuration.files.encoding;
const configuredEncoding = this.configurationService.getValue<string>(this.resource, 'files.encoding');

if (this.configuredEncoding !== configuredEncoding) {
this.configuredEncoding = configuredEncoding;
Expand Down Expand Up @@ -185,10 +184,8 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
this.setDirty(this.hasAssociatedFilePath || !!backupContent);

return this.doLoad(backupContent || this.initialValue || '').then(model => {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>(this.resource);

// Encoding
this.configuredEncoding = configuration && configuration.files && configuration.files.encoding;
this.configuredEncoding = this.configurationService.getValue<string>(this.resource, 'files.encoding');

// Listen to content changes
this.toDispose.push(this.textEditorModel.onDidChangeContent(() => this.onModelContentChanged()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function readTransientState(model: IModel, codeEditorService: ICodeEditorService
}

function readWordWrapState(model: IModel, configurationService: ITextResourceConfigurationService, codeEditorService: ICodeEditorService): IWordWrapState {
const editorConfig = configurationService.getConfiguration(model.uri, 'editor') as { wordWrap: 'on' | 'off' | 'wordWrapColumn' | 'bounded'; wordWrapMinified: boolean };
const editorConfig = configurationService.getValue(model.uri, 'editor') as { wordWrap: 'on' | 'off' | 'wordWrapColumn' | 'bounded'; wordWrapMinified: boolean };
let _configuredWordWrap = editorConfig && (typeof editorConfig.wordWrap === 'string' || typeof editorConfig.wordWrap === 'boolean') ? editorConfig.wordWrap : void 0;

// Compatibility with old true or false values
Expand Down
8 changes: 5 additions & 3 deletions src/vs/workbench/parts/output/browser/outputPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction, ToggleOu
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

export class OutputPanel extends TextResourceEditor {
private actions: IAction[];
Expand All @@ -32,14 +33,15 @@ export class OutputPanel extends TextResourceEditor {
@ITelemetryService telemetryService: ITelemetryService,
@IInstantiationService instantiationService: IInstantiationService,
@IStorageService storageService: IStorageService,
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
@IConfigurationService private baseConfigurationService: IConfigurationService,
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
@IThemeService themeService: IThemeService,
@IOutputService private outputService: IOutputService,
@IContextKeyService private contextKeyService: IContextKeyService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@ITextFileService textFileService: ITextFileService
) {
super(telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, textFileService);
super(telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, textFileService);

this.scopedInstantiationService = instantiationService;
}
Expand Down Expand Up @@ -84,7 +86,7 @@ export class OutputPanel extends TextResourceEditor {
options.renderLineHighlight = 'none';
options.minimap = { enabled: false };

const outputConfig = this.configurationService.getConfiguration(null, '[Log]');
const outputConfig = this.baseConfigurationService.getValue('[Log]');
if (outputConfig && outputConfig['editor.minimap.enabled']) {
options.minimap = { enabled: true };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MockConfigurationService implements IConfigurationService {
public inspect<T>(key: string, overrides?: IConfigurationOverrides): any { return { value: getConfigurationValue<T>(this.getConfiguration(), key), default: getConfigurationValue<T>(this.getConfiguration(), key), user: getConfigurationValue<T>(this.getConfiguration(), key), workspace: void 0, workspaceFolder: void 0 }; }
public keys() { return { default: [] as string[], user: [] as string[], workspace: [] as string[], workspaceFolder: [] as string[] }; }
public getConfiguration(): any { return this.configuration; }
public getValue<T>(key: string, overrides?: IConfigurationOverrides): T { return getConfigurationValue<T>(this.getConfiguration(), key); }
public getValue(): any { return this.configuration; }
public updateValue(): TPromise<void> { return null; }
public getConfigurationData(): any { return null; }
public onDidChangeConfiguration() { return { dispose() { } }; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,14 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
return this._configuration.getSection(section, overrides);
}

getValue<T>(key: string, overrides?: IConfigurationOverrides): T {
return this._configuration.getValue(key, overrides);
getValue<T>(): T;
getValue<T>(section: string): T;
getValue<T>(overrides: IConfigurationOverrides): T;
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
getValue(arg1?: any, arg2?: any): any {
const section = typeof arg1 === 'string' ? arg1 : void 0;
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : void 0;
return this._configuration.getValue(section, overrides);
}

updateValue(key: string, value: any): TPromise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class MockConfigurationService implements IConfigurationService {
public inspect<T>(key: string, overrides?: IConfigurationOverrides): any { return { value: getConfigurationValue<T>(this.getConfiguration(), key), default: getConfigurationValue<T>(this.getConfiguration(), key), user: getConfigurationValue<T>(this.getConfiguration(), key), workspaceFolder: void 0, folder: void 0 }; }
public keys() { return { default: [], user: [], workspace: [], workspaceFolder: [] }; }
public getConfiguration(): any { return this.configuration; }
public getValue(key: string): any { return getConfigurationValue<any>(this.getConfiguration(), key); }
public getValue(): any { return this.configuration; }
public updateValue(): TPromise<void> { return null; }
public getConfigurationData(): any { return null; }
public onDidChangeConfiguration() { return { dispose() { } }; }
Expand Down
10 changes: 3 additions & 7 deletions src/vs/workbench/services/files/node/fileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import os = require('os');
import crypto = require('crypto');
import assert = require('assert');

import { isParent, FileOperation, FileOperationEvent, IContent, IFileService, IResolveFileOptions, IResolveFileResult, IResolveContentOptions, IFileStat, IStreamContent, FileOperationError, FileOperationResult, IUpdateContentOptions, FileChangeType, IImportResult, MAX_FILE_SIZE, FileChangesEvent, IFilesConfiguration, ICreateFileOptions } from 'vs/platform/files/common/files';
import { isParent, FileOperation, FileOperationEvent, IContent, IFileService, IResolveFileOptions, IResolveFileResult, IResolveContentOptions, IFileStat, IStreamContent, FileOperationError, FileOperationResult, IUpdateContentOptions, FileChangeType, IImportResult, MAX_FILE_SIZE, FileChangesEvent, ICreateFileOptions } from 'vs/platform/files/common/files';
import { isEqualOrParent } from 'vs/base/common/paths';
import { ResourceMap } from 'vs/base/common/map';
import arrays = require('vs/base/common/arrays');
Expand Down Expand Up @@ -643,15 +643,11 @@ export class FileService implements IFileService {
}

private configuredAutoGuessEncoding(resource: uri): boolean {
const config = this.textResourceConfigurationService.getConfiguration(resource) as IFilesConfiguration;

return config && config.files && config.files.autoGuessEncoding === true;
return this.textResourceConfigurationService.getValue(resource, 'files.autoGuessEncoding');
}

private configuredEncoding(resource: uri): string {
const config = this.textResourceConfigurationService.getConfiguration(resource) as IFilesConfiguration;

return config && config.files && config.files.encoding;
return this.textResourceConfigurationService.getValue(resource, 'files.encoding');
}

private getEncodingOverride(resource: uri): string {
Expand Down
Loading

0 comments on commit 6f03367

Please sign in to comment.