提交 1de7a23c 编写于 作者: B Benjamin Pasero

code clean up

上级 a4bc82cb
......@@ -44,7 +44,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
private loaded: boolean;
private timeoutHandle: number;
private disposables: IDisposable[];
private _onDidUpdateConfiguration:Emitter<IConfigurationChangeEvent<T>>;
private _onDidUpdateConfiguration: Emitter<IConfigurationChangeEvent<T>>;
constructor(private _path: string, private options: IConfigOptions<T> = { changeBufferDelay: 0, defaultConfig: Object.create(null) }) {
this.disposables = [];
......@@ -82,14 +82,11 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
}
private loadSync(): T {
let raw: string;
try {
raw = fs.readFileSync(this._path).toString();
return this.parse(fs.readFileSync(this._path).toString());
} catch (error) {
return this.options.defaultConfig;
}
return this.parse(raw);
}
private loadAsync(callback: (config: T) => void): void {
......@@ -108,7 +105,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
this.parseErrors = [];
res = json.parse(raw, this.parseErrors);
} catch (error) {
// Ignore loading and parsing errors
// Ignore parsing errors
}
return res || this.options.defaultConfig;
......@@ -155,16 +152,13 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
}
private onConfigFileChange(): void {
// we can get multiple change events for one change, so we buffer through a timeout
if (this.timeoutHandle) {
global.clearTimeout(this.timeoutHandle);
this.timeoutHandle = null;
}
this.timeoutHandle = global.setTimeout(() => {
this.reload();
}, this.options.changeBufferDelay);
// we can get multiple change events for one change, so we buffer through a timeout
this.timeoutHandle = global.setTimeout(() => this.reload(), this.options.changeBufferDelay);
}
public reload(callback?: (config: T) => void): void {
......
......@@ -69,7 +69,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
const windowsService = accessor.get(IWindowsService);
const lifecycleService = accessor.get(ILifecycleService);
const updateService = accessor.get(IUpdateService);
const configurationService = <ConfigurationService>accessor.get(IConfigurationService);
const configurationService = <ConfigurationService<any>>accessor.get(IConfigurationService);
// We handle uncaught exceptions here to prevent electron from opening a dialog to the user
process.on('uncaughtException', (err: any) => {
......
......@@ -16,14 +16,14 @@ import {IConfigurationService, IConfigurationServiceEvent } from 'vs/platform/co
import Event, {Emitter} from 'vs/base/common/event';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
export class ConfigurationService implements IConfigurationService, IDisposable {
export class ConfigurationService<T> implements IConfigurationService, IDisposable {
_serviceBrand: any;
private disposables: IDisposable[];
private rawConfig: ConfigWatcher<any>;
private cache: any;
private rawConfig: ConfigWatcher<T>;
private cache: T;
private _onDidUpdateConfiguration: Emitter<IConfigurationServiceEvent>;
......@@ -53,17 +53,17 @@ export class ConfigurationService implements IConfigurationService, IDisposable
return this._onDidUpdateConfiguration.event;
}
public loadConfiguration<T>(section?: string): TPromise<T> {
return new TPromise<T>(c => {
public loadConfiguration<C>(section?: string): TPromise<C> {
return new TPromise<C>(c => {
this.rawConfig.reload(() => {
this.cache = void 0; // reset our caches
c(this.getConfiguration<T>(section));
c(this.getConfiguration<C>(section));
});
});
}
public getConfiguration<T>(section?: string): T {
public getConfiguration<C>(section?: string): C {
let consolidatedConfig = this.cache;
if (!consolidatedConfig) {
consolidatedConfig = this.getConsolidatedConfig();
......@@ -73,7 +73,7 @@ export class ConfigurationService implements IConfigurationService, IDisposable
return section ? consolidatedConfig[section] : consolidatedConfig;
}
private getConsolidatedConfig(): any {
private getConsolidatedConfig(): T {
const defaults = getDefaultValues(); // defaults coming from contributions to registries
const user = flatten(this.rawConfig.getConfig()); // user configured settings
......
......@@ -452,7 +452,8 @@ export enum FileOperationResult {
FILE_MODIFIED_SINCE,
FILE_MOVE_CONFLICT,
FILE_READ_ONLY,
FILE_TOO_LARGE
FILE_TOO_LARGE,
FILE_INVALID_PATH
}
export const MAX_FILE_SIZE = 50 * 1024 * 1024;
......
......@@ -25,7 +25,7 @@ export abstract class KeybindingService implements IKeybindingService {
public _serviceBrand: any;
protected toDispose: IDisposable[] = [];
private _cachedResolver: KeybindingResolver;
private _firstTimeComputingResolver: boolean;
private _currentChord: number;
......@@ -181,6 +181,4 @@ export abstract class KeybindingService implements IKeybindingService {
});
}
}
}
}
\ No newline at end of file
......@@ -153,7 +153,8 @@ export class FileService implements IFileService {
// Guard early against attempts to resolve an invalid file path
if (resource.scheme !== 'file' || !resource.fsPath) {
return TPromise.wrapError(<IFileOperationResult>{
message: nls.localize('fileInvalidPath', "Invalid file resource ({0})", resource.toString())
message: nls.localize('fileInvalidPath', "Invalid file resource ({0})", resource.toString()),
fileOperationResult: FileOperationResult.FILE_INVALID_PATH
});
}
......
......@@ -9,6 +9,7 @@ import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {IJSONSchema} from 'vs/base/common/jsonSchema';
import {Keybinding} from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import {toDisposable} from 'vs/base/common/lifecycle';
import {IEventService} from 'vs/platform/event/common/event';
import {IExtensionMessageCollector, ExtensionsRegistry} from 'vs/platform/extensions/common/extensionsRegistry';
import {Extensions, IJSONContributionRegistry} from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
......@@ -131,6 +132,7 @@ export class WorkbenchKeybindingService extends KeybindingService {
super(contextKeyService, commandService, messageService, statusBarService);
this.userKeybindings = new ConfigWatcher(environmentService.appKeybindingsPath, { defaultConfig: [] });
this.toDispose.push(toDisposable(() => this.userKeybindings.dispose()));
keybindingsExtPoint.setHandler((extensions) => {
let commandAdded = false;
......@@ -168,12 +170,6 @@ export class WorkbenchKeybindingService extends KeybindingService {
return extraUserKeybindings.map((k, i) => IOSupport.readKeybindingItem(k, i));
}
public dispose(): void {
super.dispose();
this.userKeybindings.dispose();
}
public getLabelFor(keybinding: Keybinding): string {
return keybinding.toCustomLabel(getNativeLabelProvider());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册