Skip to content

Commit a28ee70

Browse files
committed
[880] feature settings promisedelegate
1 parent 3fe641e commit a28ee70

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

packages/jupyterlab-lsp/src/feature.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IDocumentWidget } from '@jupyterlab/docregistry';
33
import { ISettingRegistry } from '@jupyterlab/settingregistry';
44
import { TranslationBundle } from '@jupyterlab/translation';
55
import { LabIcon } from '@jupyterlab/ui-components';
6+
import { PromiseDelegate } from '@lumino/coreutils';
67
import { Signal } from '@lumino/signaling';
78

89
import { StatusMessage, WidgetAdapter } from './adapters/adapter';
@@ -65,32 +66,34 @@ export interface IFeatureSettings<T> {
6566
export class FeatureSettings<T> implements IFeatureSettings<T> {
6667
protected settings: ISettingRegistry.ISettings;
6768
public changed: Signal<FeatureSettings<T>, void>;
68-
public ready: Promise<void>;
69+
private _ready = new PromiseDelegate<void>();
6970

7071
constructor(protected settingRegistry: ISettingRegistry, featureID: string) {
7172
this.changed = new Signal(this);
7273
if (!(featureID in settingRegistry.plugins)) {
73-
console.warn(
74+
this._ready.reject(
7475
`${featureID} settings schema could not be found and was not loaded`
7576
);
7677
} else {
77-
this.ready = new Promise(accept => {
78-
settingRegistry
79-
.load(featureID)
80-
.then(settings => {
78+
settingRegistry
79+
.load(featureID)
80+
.then(settings => {
81+
this.settings = settings;
82+
this._ready.resolve(void 0);
83+
this.changed.emit();
84+
settings.changed.connect(() => {
8185
this.settings = settings;
82-
accept();
8386
this.changed.emit();
84-
settings.changed.connect(() => {
85-
this.settings = settings;
86-
this.changed.emit();
87-
});
88-
})
89-
.catch(console.warn);
90-
});
87+
});
88+
})
89+
.catch(console.warn);
9190
}
9291
}
9392

93+
get ready(): Promise<void> {
94+
return this._ready.promise;
95+
}
96+
9497
get composite(): Required<T> {
9598
return this.settings.composite as unknown as Required<T>;
9699
}

0 commit comments

Comments
 (0)