Skip to content

Commit 181f0d1

Browse files
committed
Use CancellationToken in completion provider
1 parent e2d772b commit 181f0d1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/completionProvider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
8484
const items: CompletionItem[] = [];
8585
const line = doc.lineAt(pos);
8686
const precedingText = line.text.substring(0, pos.character - 1).trim();
87-
88-
if (this.shouldProvideItems(precedingText, pos, doc)) {
87+
88+
if (this.shouldProvideItems(precedingText, pos, doc) && !token.isCancellationRequested) {
8989
const param = this.getParam(precedingText);
9090
const documentText = doc.getText();
9191
const typeContainer = getDataTypeContainer();
9292
const provider = new TypeHintProvider(typeContainer);
9393
const wsSearcher = new WorkspaceSearcher(doc.uri, this.settings, typeContainer);
9494
let estimations: string[] = [];
9595

96-
if (param) {
96+
if (param && !token.isCancellationRequested) {
9797
const workspaceHintSearch = this.settings.workspaceSearchEnabled
9898
? this.workspaceHintSearch(param, wsSearcher, documentText)
9999
: null;
@@ -106,6 +106,10 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
106106
} catch {
107107
}
108108

109+
if (token.isCancellationRequested) {
110+
wsSearcher.cancel();
111+
return Promise.resolve(null);
112+
}
109113
this.pushHintsToItems(provider.remainingTypeHints(), items, estimations.length === 0);
110114
this.itemSortPrefix++;
111115
this.pushHintsToItems(provider.remainingTypingHints(), items, false);

src/workspaceSearcher.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export class WorkspaceSearcher {
5858
* Stops all searches.
5959
*/
6060
public cancel() {
61-
this.tokenSource.cancel();
62-
this.search = false;
61+
if (this.search) {
62+
this.search = false;
63+
this.tokenSource.cancel();
64+
}
6365
}
6466
}

0 commit comments

Comments
 (0)