Skip to content

Commit 816b66c

Browse files
Move withProgress out of loadExternalApiUsages
1 parent a3ce9f5 commit 816b66c

File tree

1 file changed

+57
-45
lines changed

1 file changed

+57
-45
lines changed

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ export class ModelEditorView extends AbstractWebview<
190190

191191
break;
192192
case "refreshMethods":
193-
await this.loadExternalApiUsages();
193+
await withProgress((progress) => this.loadExternalApiUsages(progress), {
194+
cancellable: false,
195+
});
196+
194197
void telemetryListener?.sendUIInteraction(
195198
"model-editor-refresh-methods",
196199
);
@@ -212,7 +215,12 @@ export class ModelEditorView extends AbstractWebview<
212215
this.cliServer,
213216
this.app.logger,
214217
);
215-
await Promise.all([this.setViewState(), this.loadExternalApiUsages()]);
218+
await Promise.all([
219+
this.setViewState(),
220+
withProgress((progress) => this.loadExternalApiUsages(progress), {
221+
cancellable: false,
222+
}),
223+
]);
216224
void telemetryListener?.sendUIInteraction(
217225
"model-editor-save-modeled-methods",
218226
);
@@ -249,7 +257,12 @@ export class ModelEditorView extends AbstractWebview<
249257
break;
250258
case "switchMode":
251259
this.mode = msg.mode;
252-
await Promise.all([this.setViewState(), this.loadExternalApiUsages()]);
260+
await Promise.all([
261+
this.setViewState(),
262+
withProgress((progress) => this.loadExternalApiUsages(progress), {
263+
cancellable: false,
264+
}),
265+
]);
253266
void telemetryListener?.sendUIInteraction("model-editor-switch-modes");
254267

255268
break;
@@ -274,7 +287,9 @@ export class ModelEditorView extends AbstractWebview<
274287

275288
await Promise.all([
276289
this.setViewState(),
277-
this.loadExternalApiUsages(),
290+
withProgress((progress) => this.loadExternalApiUsages(progress), {
291+
cancellable: false,
292+
}),
278293
this.loadExistingModeledMethods(),
279294
]);
280295
}
@@ -317,48 +332,45 @@ export class ModelEditorView extends AbstractWebview<
317332
}
318333
}
319334

320-
protected async loadExternalApiUsages(): Promise<void> {
321-
await withProgress(
322-
async (progress) => {
323-
try {
324-
const cancellationTokenSource = new CancellationTokenSource();
325-
const queryResult = await runExternalApiQueries(this.mode, {
326-
cliServer: this.cliServer,
327-
queryRunner: this.queryRunner,
328-
databaseItem: this.databaseItem,
329-
queryStorageDir: this.queryStorageDir,
330-
queryDir: this.queryDir,
331-
progress: (update) => progress({ ...update, maxStep: 1500 }),
332-
token: cancellationTokenSource.token,
333-
});
334-
if (!queryResult) {
335-
return;
336-
}
337-
this.methods = queryResult;
335+
protected async loadExternalApiUsages(
336+
progress: ProgressCallback,
337+
): Promise<void> {
338+
try {
339+
const cancellationTokenSource = new CancellationTokenSource();
340+
const queryResult = await runExternalApiQueries(this.mode, {
341+
cliServer: this.cliServer,
342+
queryRunner: this.queryRunner,
343+
databaseItem: this.databaseItem,
344+
queryStorageDir: this.queryStorageDir,
345+
queryDir: this.queryDir,
346+
progress: (update) => progress({ ...update, maxStep: 1500 }),
347+
token: cancellationTokenSource.token,
348+
});
349+
if (!queryResult) {
350+
return;
351+
}
352+
this.methods = queryResult;
338353

339-
await this.postMessage({
340-
t: "setMethods",
341-
methods: this.methods,
342-
});
343-
if (this.isMostRecentlyActiveView(this)) {
344-
await this.updateMethodsUsagePanelState(
345-
this.methods,
346-
this.databaseItem,
347-
this.hideModeledApis,
348-
);
349-
}
350-
} catch (err) {
351-
void showAndLogExceptionWithTelemetry(
352-
this.app.logger,
353-
this.app.telemetry,
354-
redactableError(
355-
asError(err),
356-
)`Failed to load external API usages: ${getErrorMessage(err)}`,
357-
);
358-
}
359-
},
360-
{ cancellable: false },
361-
);
354+
await this.postMessage({
355+
t: "setMethods",
356+
methods: this.methods,
357+
});
358+
if (this.isMostRecentlyActiveView(this)) {
359+
await this.updateMethodsUsagePanelState(
360+
this.methods,
361+
this.databaseItem,
362+
this.hideModeledApis,
363+
);
364+
}
365+
} catch (err) {
366+
void showAndLogExceptionWithTelemetry(
367+
this.app.logger,
368+
this.app.telemetry,
369+
redactableError(
370+
asError(err),
371+
)`Failed to load external API usages: ${getErrorMessage(err)}`,
372+
);
373+
}
362374
}
363375

364376
protected async generateModeledMethods(): Promise<void> {

0 commit comments

Comments
 (0)