提交 0a2d071e 编写于 作者: M Matt Bierner

Strict null checking config

上级 f742c33a
......@@ -66,6 +66,7 @@
"./vs/base/common/jsonFormatter.ts",
"./vs/base/common/paths.ts",
"./vs/base/common/uriIpc.ts",
"./vs/base/node/config.ts",
"./vs/base/node/console.ts",
"./vs/base/node/crypto.ts",
"./vs/base/node/decoder.ts",
......@@ -94,6 +95,7 @@
"./vs/base/parts/ipc/test/node/testApp.ts",
"./vs/base/parts/ipc/test/node/testService.ts",
"./vs/base/parts/quickopen/common/quickOpen.ts",
"./vs/base/parts/quickopen/common/quickOpenScorer.ts",
"./vs/base/test/browser/ui/grid/util.ts",
"./vs/base/test/common/json.test.ts",
"./vs/base/test/common/jsonEdit.test.ts",
......@@ -468,6 +470,12 @@
"./vs/platform/quickOpen/common/quickOpen.ts",
"./vs/platform/quickinput/common/quickInput.ts",
"./vs/platform/registry/common/platform.ts",
"./vs/platform/remote/common/remoteAuthorityResolver.ts",
"./vs/platform/remote/common/remoteHosts.ts",
"./vs/platform/remote/node/remoteAgentConnection.ts",
"./vs/platform/remote/node/remoteAgentFileSystemChannel.ts",
"./vs/platform/remote/node/remoteAuthorityResolverChannel.ts",
"./vs/platform/remote/node/remoteAuthorityResolverService.ts",
"./vs/platform/request/electron-browser/requestService.ts",
"./vs/platform/request/electron-main/requestService.ts",
"./vs/platform/request/node/request.ts",
......@@ -652,10 +660,13 @@
"./vs/workbench/services/keybinding/common/macLinuxFallbackKeyboardMapper.ts",
"./vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts",
"./vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts",
"./vs/workbench/services/keybinding/electron-browser/keybindingService.ts",
"./vs/workbench/services/mode/common/workbenchModeService.ts",
"./vs/workbench/services/notification/common/notificationService.ts",
"./vs/workbench/services/panel/common/panelService.ts",
"./vs/workbench/services/part/common/partService.ts",
"./vs/workbench/services/remote/node/remoteAgentEnvironmentChannel.ts",
"./vs/workbench/services/remote/node/remoteAgentService.ts",
"./vs/workbench/services/scm/common/scm.ts",
"./vs/workbench/services/scm/common/scmService.ts",
"./vs/workbench/services/search/common/searchHelpers.ts",
......@@ -680,8 +691,7 @@
"./vs/workbench/services/themes/common/workbenchThemeService.ts",
"./vs/workbench/services/title/common/titleService.ts",
"./vs/workbench/services/workspace/common/workspaceEditing.ts",
"./vs/workbench/test/electron-browser/api/mock.ts",
"./vs/base/parts/quickopen/common/quickOpenScorer.ts"
"./vs/workbench/test/electron-browser/api/mock.ts"
],
"exclude": [
"./typings/require-monaco.d.ts",
......
......@@ -13,7 +13,7 @@ import * as extfs from 'vs/base/node/extfs';
import { isWindows } from 'vs/base/common/platform';
export interface IConfigurationChangeEvent<T> {
config: T;
config?: T;
}
export interface IConfigWatcher<T> {
......@@ -21,8 +21,8 @@ export interface IConfigWatcher<T> {
hasParseErrors: boolean;
reload(callback: (config: T) => void): void;
getConfig(): T;
getValue<V>(key: string, fallback?: V): V;
getConfig(): T | undefined;
getValue<V>(key: string, fallback?: V): V | undefined;
}
export interface IConfigOptions<T> {
......@@ -30,7 +30,7 @@ export interface IConfigOptions<T> {
defaultConfig?: T;
changeBufferDelay?: number;
parse?: (content: string, errors: any[]) => T;
initCallback?: (config: T) => void;
initCallback?: (config: T | undefined) => void;
}
/**
......@@ -42,11 +42,11 @@ export interface IConfigOptions<T> {
* - configurable defaults
*/
export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
private cache: T;
private cache?: T;
private parseErrors: json.ParseError[];
private disposed: boolean;
private loaded: boolean;
private timeoutHandle: NodeJS.Timer;
private timeoutHandle: any;
private disposables: IDisposable[];
private readonly _onDidUpdateConfiguration: Emitter<IConfigurationChangeEvent<T>>;
private configName: string;
......@@ -85,12 +85,12 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
});
}
private updateCache(value: T): void {
private updateCache(value: T | undefined): void {
this.cache = value;
this.loaded = true;
}
private loadSync(): T {
private loadSync(): T | undefined {
try {
return this.parse(fs.readFileSync(this._path).toString());
} catch (error) {
......@@ -98,7 +98,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
}
}
private loadAsync(callback: (config: T) => void): void {
private loadAsync(callback: (config: T | undefined) => void): void {
fs.readFile(this._path, (error, raw) => {
if (error) {
return callback(this.options.defaultConfig);
......@@ -108,8 +108,8 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
});
}
private parse(raw: string): T {
let res: T;
private parse(raw: string): T | undefined {
let res: T | undefined;
try {
this.parseErrors = [];
res = this.options.parse ? this.options.parse(raw, this.parseErrors) : json.parse(raw, this.parseErrors);
......@@ -156,7 +156,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
));
}
private onConfigFileChange(eventType: string, filename: string, isParentFolder: boolean): void {
private onConfigFileChange(eventType: string, filename: string | undefined, isParentFolder: boolean): void {
if (isParentFolder) {
// Windows: in some cases the filename contains artifacts from the absolute path
......@@ -177,10 +177,10 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
}
// we can get multiple change events for one change, so we buffer through a timeout
this.timeoutHandle = global.setTimeout(() => this.reload(), this.options.changeBufferDelay);
this.timeoutHandle = global.setTimeout(() => this.reload(), this.options.changeBufferDelay || 0);
}
public reload(callback?: (config: T) => void): void {
public reload(callback?: (config: T | undefined) => void): void {
this.loadAsync(currentConfig => {
if (!objects.equals(currentConfig, this.cache)) {
this.updateCache(currentConfig);
......@@ -194,13 +194,13 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
});
}
public getConfig(): T {
public getConfig(): T | undefined {
this.ensureLoaded();
return this.cache;
}
public getValue<V>(key: string, fallback?: V): V {
public getValue<V>(key: string, fallback?: V): V | undefined {
this.ensureLoaded();
if (!key) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册