Skip to content

Commit

Permalink
fix workspace preference provider
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
  • Loading branch information
akurinnoy committed Jun 12, 2018
1 parent 9694094 commit 56b94e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
@postConstruct()
protected async init(): Promise<void> {
const uri = await this.getUri();

// In case if no workspace is opened there are no workspace settings.
// There is nothing to contribute to preferences and we just skip it.
if (!uri) {
this._ready.resolve();
return;
}
this.resource = this.resourceProvider(uri);

// Try to read the initial content of the preferences. The provider
Expand All @@ -41,7 +48,7 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
}
}

abstract getUri(): MaybePromise<URI>;
abstract getUri(): MaybePromise<URI | undefined>;

getPreferences(): { [key: string]: any } {
return this.preferences;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export class PreferenceFrontendContribution implements CommandContribution, Menu

protected async openWorkspacePreferences(): Promise<void> {
const wsUri = await this.workspacePreferenceProvider.getUri();
if (!wsUri) {
return;
}
if (!(await this.filesystem.exists(wsUri.toString()))) {
await this.filesystem.createFile(wsUri.toString(), { content: this.getPreferenceTemplateForScope('workspace') });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export class WorkspacePreferenceProvider extends AbstractResourcePreferenceProvi
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

async getUri(): Promise<URI> {
async getUri(): Promise<URI | undefined> {
const root = await this.workspaceService.root;
if (root) {
const rootUri = new URI(root.uri);
return rootUri.resolve('.theia').resolve('settings.json');
}
return new Promise<URI>(() => { });
return undefined;
}

}

0 comments on commit 56b94e6

Please sign in to comment.