提交 48e3f6c8 编写于 作者: M Matt Bierner

Working on strict null checking configuration

上级 4be6af93
...@@ -65,7 +65,7 @@ export class WorkspaceConfiguration extends Disposable { ...@@ -65,7 +65,7 @@ export class WorkspaceConfiguration extends Disposable {
parseErrors = [...this._workspaceConfigurationModelParser.errors]; parseErrors = [...this._workspaceConfigurationModelParser.errors];
this.consolidate(); this.consolidate();
return this._workspaceConfigurationModelParser; return this._workspaceConfigurationModelParser;
}, initCallback: () => c(null) }, initCallback: () => c(void 0)
}); });
this.listenToWatcher(); this.listenToWatcher();
}); });
...@@ -75,7 +75,7 @@ export class WorkspaceConfiguration extends Disposable { ...@@ -75,7 +75,7 @@ export class WorkspaceConfiguration extends Disposable {
this.stopListeningToWatcher(); this.stopListeningToWatcher();
return new Promise<void>(c => this._workspaceConfigurationWatcher.reload(() => { return new Promise<void>(c => this._workspaceConfigurationWatcher.reload(() => {
this.listenToWatcher(); this.listenToWatcher();
c(null); c(void 0);
})); }));
} }
...@@ -225,13 +225,16 @@ export class NodeBasedFolderConfiguration extends AbstractFolderConfiguration { ...@@ -225,13 +225,16 @@ export class NodeBasedFolderConfiguration extends AbstractFolderConfiguration {
protected loadFolderConfigurationContents(): Promise<{ resource: URI, value: string }[]> { protected loadFolderConfigurationContents(): Promise<{ resource: URI, value: string }[]> {
return this.resolveStat(this.folderConfigurationPath).then(stat => { return this.resolveStat(this.folderConfigurationPath).then(stat => {
if (!stat.isDirectory) { if (!stat.isDirectory || !stat.children) {
return Promise.resolve([]); return Promise.resolve([]);
} }
return this.resolveContents(stat.children.filter(stat => isFolderConfigurationFile(stat.resource)) return this.resolveContents(stat.children.filter(stat => isFolderConfigurationFile(stat.resource))
.map(stat => stat.resource)); .map(stat => stat.resource));
}, err => [] /* never fail this call */) }, err => [] /* never fail this call */)
.then(void 0, errors.onUnexpectedError); .then(void 0, e => {
errors.onUnexpectedError(e);
return [];
});
} }
private resolveContents(resources: URI[]): Promise<{ resource: URI, value: string }[]> { private resolveContents(resources: URI[]): Promise<{ resource: URI, value: string }[]> {
...@@ -265,7 +268,7 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura ...@@ -265,7 +268,7 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura
private reloadConfigurationScheduler: RunOnceScheduler; private reloadConfigurationScheduler: RunOnceScheduler;
private readonly folderConfigurationPath: URI; private readonly folderConfigurationPath: URI;
private readonly loadConfigurationDelayer: Delayer<{ resource: URI, value: string }[]> = new Delayer<{ resource: URI, value: string }[]>(50); private readonly loadConfigurationDelayer = new Delayer<Array<{ resource: URI, value: string }>>(50);
constructor(folder: URI, private configFolderRelativePath: string, workbenchState: WorkbenchState, private fileService: IFileService, from?: AbstractFolderConfiguration) { constructor(folder: URI, private configFolderRelativePath: string, workbenchState: WorkbenchState, private fileService: IFileService, from?: AbstractFolderConfiguration) {
super(folder, workbenchState, from); super(folder, workbenchState, from);
...@@ -274,18 +277,23 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura ...@@ -274,18 +277,23 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura
this._register(fileService.onFileChanges(e => this.handleWorkspaceFileEvents(e))); this._register(fileService.onFileChanges(e => this.handleWorkspaceFileEvents(e)));
} }
protected loadFolderConfigurationContents(): Promise<{ resource: URI, value: string }[]> { protected loadFolderConfigurationContents(): Promise<Array<{ resource: URI, value: string }>> {
return Promise.resolve(this.loadConfigurationDelayer.trigger(() => this.doLoadFolderConfigurationContents())); return Promise.resolve(this.loadConfigurationDelayer.trigger(() => this.doLoadFolderConfigurationContents()));
} }
private doLoadFolderConfigurationContents(): Promise<{ resource: URI, value: string }[]> { private doLoadFolderConfigurationContents(): Promise<Array<{ resource: URI, value: string }>> {
const workspaceFilePathToConfiguration: { [relativeWorkspacePath: string]: Promise<IContent> } = Object.create(null); const workspaceFilePathToConfiguration: { [relativeWorkspacePath: string]: Promise<IContent> } = Object.create(null);
const bulkContentFetchromise = Promise.resolve(this.fileService.resolveFile(this.folderConfigurationPath)) const bulkContentFetchromise = Promise.resolve(this.fileService.resolveFile(this.folderConfigurationPath))
.then(stat => { .then(stat => {
if (stat.isDirectory && stat.children) { if (stat.isDirectory && stat.children) {
stat.children stat.children
.filter(child => isFolderConfigurationFile(child.resource)) .filter(child => isFolderConfigurationFile(child.resource))
.forEach(child => workspaceFilePathToConfiguration[this.toFolderRelativePath(child.resource)] = Promise.resolve(this.fileService.resolveContent(child.resource)).then(void 0, errors.onUnexpectedError)); .forEach(child => {
const folderRelativePath = this.toFolderRelativePath(child.resource);
if (folderRelativePath) {
workspaceFilePathToConfiguration[folderRelativePath] = Promise.resolve(this.fileService.resolveContent(child.resource)).then(void 0, errors.onUnexpectedError);
}
});
} }
}).then(void 0, err => [] /* never fail this call */); }).then(void 0, err => [] /* never fail this call */);
...@@ -336,7 +344,7 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura ...@@ -336,7 +344,7 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura
} }
} }
private toFolderRelativePath(resource: URI): string { private toFolderRelativePath(resource: URI): string | null {
if (resource.scheme === Schemas.file) { if (resource.scheme === Schemas.file) {
if (paths.isEqualOrParent(resource.fsPath, this.folderConfigurationPath.fsPath, !isLinux /* ignorecase */)) { if (paths.isEqualOrParent(resource.fsPath, this.folderConfigurationPath.fsPath, !isLinux /* ignorecase */)) {
return paths.normalize(relative(this.folderConfigurationPath.fsPath, resource.fsPath)); return paths.normalize(relative(this.folderConfigurationPath.fsPath, resource.fsPath));
...@@ -387,7 +395,7 @@ export class CachedFolderConfiguration extends Disposable implements IFolderConf ...@@ -387,7 +395,7 @@ export class CachedFolderConfiguration extends Disposable implements IFolderConf
if (created) { if (created) {
return configurationModel.keys.length ? pfs.writeFile(this.cachedConfigurationPath, raw) : pfs.rimraf(this.cachedFolderPath); return configurationModel.keys.length ? pfs.writeFile(this.cachedConfigurationPath, raw) : pfs.rimraf(this.cachedFolderPath);
} }
return null; return void 0;
}); });
} }
...@@ -492,6 +500,6 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat ...@@ -492,6 +500,6 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat
return this.folderConfiguration.loadConfiguration() return this.folderConfiguration.loadConfiguration()
.then(configurationModel => this.cachedFolderConfiguration.updateConfiguration(configurationModel)); .then(configurationModel => this.cachedFolderConfiguration.updateConfiguration(configurationModel));
} }
return Promise.resolve(null); return Promise.resolve(void 0);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册