Skip to content

Commit

Permalink
Expose processedItemsCache as a protected member (jupyterlab#15025)
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored Aug 28, 2023
1 parent 681f894 commit 93a4a56
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/completer/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class CompleterModel implements Completer.IModel {
const ending = original.text.substring(end);
query = query.substring(0, query.lastIndexOf(ending));
this._query = query;
this._processedItemsCache = null;
this.processedItemsCache = null;
this._queryChanged.emit({ newValue: this._query, origin: 'editorUpdate' });
this._stateChanged.emit(undefined);
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export class CompleterModel implements Completer.IModel {
}
set query(newValue: string) {
this._query = newValue;
this._processedItemsCache = null;
this.processedItemsCache = null;
this._queryChanged.emit({ newValue: this._query, origin: 'setter' });
}

Expand Down Expand Up @@ -180,19 +180,21 @@ export class CompleterModel implements Completer.IModel {
*
* #### Notes
* This is a read-only property.
* When overriding it is recommended to cache results in `processedItemsCache`
* property which will be automatically nullified when needed.
*/
completionItems(): CompletionHandler.ICompletionItems {
if (!this._processedItemsCache) {
if (!this.processedItemsCache) {
let query = this._query;
if (query) {
this._processedItemsCache = this._markup(query);
this.processedItemsCache = this._markup(query);
} else {
this._processedItemsCache = this._completionItems.map(item => {
this.processedItemsCache = this._completionItems.map(item => {
return this._escapeItemLabel(item);
});
}
}
return this._processedItemsCache;
return this.processedItemsCache;
}

/**
Expand All @@ -212,7 +214,7 @@ export class CompleterModel implements Completer.IModel {
this._orderedTypes = Private.findOrderedCompletionItemTypes(
this._completionItems
);
this._processedItemsCache = null;
this.processedItemsCache = null;
this._stateChanged.emit(undefined);
}

Expand Down Expand Up @@ -486,7 +488,7 @@ export class CompleterModel implements Completer.IModel {
this._completionItems = [];
this._original = null;
this._query = '';
this._processedItemsCache = null;
this.processedItemsCache = null;
this._subsetMatch = false;
this._typeMap = {};
this._orderedTypes = [];
Expand All @@ -495,12 +497,12 @@ export class CompleterModel implements Completer.IModel {
}
}

protected processedItemsCache: CompletionHandler.ICompletionItems | null =
null;
private _current: Completer.ITextState | null = null;
private _cursor: Completer.ICursorSpan | null = null;
private _isDisposed = false;
private _completionItems: CompletionHandler.ICompletionItems = [];
private _processedItemsCache: CompletionHandler.ICompletionItems | null =
null;
private _original: Completer.ITextState | null = null;
private _query = '';
private _subsetMatch = false;
Expand Down

0 comments on commit 93a4a56

Please sign in to comment.