|
1 | 1 | import type { CancellationToken, Tab } from "vscode"; |
2 | 2 | import { |
3 | 3 | CancellationTokenSource, |
| 4 | + ProgressLocation, |
4 | 5 | TabInputWebview, |
5 | 6 | Uri, |
6 | 7 | ViewColumn, |
@@ -53,6 +54,9 @@ import { getModelsAsDataLanguage } from "./languages"; |
53 | 54 | import { runGenerateQueries } from "./generate"; |
54 | 55 | import { ResponseError } from "vscode-jsonrpc"; |
55 | 56 | import { LSPErrorCodes } from "vscode-languageclient"; |
| 57 | +import type { AccessPathSuggestionOptions } from "./suggestions"; |
| 58 | +import { runSuggestionsQuery } from "./suggestion-queries"; |
| 59 | +import { parseAccessPathSuggestionRowsToOptions } from "./suggestions-bqrs"; |
56 | 60 |
|
57 | 61 | export class ModelEditorView extends AbstractWebview< |
58 | 62 | ToModelEditorMessage, |
@@ -305,6 +309,17 @@ export class ModelEditorView extends AbstractWebview< |
305 | 309 | withProgress((progress) => this.loadMethods(progress), { |
306 | 310 | cancellable: false, |
307 | 311 | }), |
| 312 | + // Only load access path suggestions if the feature is enabled |
| 313 | + this.modelConfig.enableAccessPathSuggestions |
| 314 | + ? withProgress( |
| 315 | + (progress) => this.loadAccessPathSuggestions(progress), |
| 316 | + { |
| 317 | + cancellable: false, |
| 318 | + location: ProgressLocation.Window, |
| 319 | + title: "Loading access path suggestions", |
| 320 | + }, |
| 321 | + ) |
| 322 | + : undefined, |
308 | 323 | ]); |
309 | 324 | void telemetryListener?.sendUIInteraction("model-editor-switch-modes"); |
310 | 325 |
|
@@ -348,6 +363,14 @@ export class ModelEditorView extends AbstractWebview< |
348 | 363 | cancellable: true, |
349 | 364 | }), |
350 | 365 | this.loadExistingModeledMethods(), |
| 366 | + // Only load access path suggestions if the feature is enabled |
| 367 | + this.modelConfig.enableAccessPathSuggestions |
| 368 | + ? withProgress((progress) => this.loadAccessPathSuggestions(progress), { |
| 369 | + cancellable: false, |
| 370 | + location: ProgressLocation.Window, |
| 371 | + title: "Loading access path suggestions", |
| 372 | + }) |
| 373 | + : undefined, |
351 | 374 | ]); |
352 | 375 | } |
353 | 376 |
|
@@ -485,6 +508,60 @@ export class ModelEditorView extends AbstractWebview< |
485 | 508 | } |
486 | 509 | } |
487 | 510 |
|
| 511 | + protected async loadAccessPathSuggestions( |
| 512 | + progress: ProgressCallback, |
| 513 | + ): Promise<void> { |
| 514 | + const tokenSource = new CancellationTokenSource(); |
| 515 | + |
| 516 | + const mode = this.modelingStore.getMode(this.databaseItem); |
| 517 | + |
| 518 | + const modelsAsDataLanguage = getModelsAsDataLanguage(this.language); |
| 519 | + const accessPathSuggestions = modelsAsDataLanguage.accessPathSuggestions; |
| 520 | + if (!accessPathSuggestions) { |
| 521 | + return; |
| 522 | + } |
| 523 | + |
| 524 | + try { |
| 525 | + const suggestions = await runSuggestionsQuery(mode, { |
| 526 | + parseResults: (results) => |
| 527 | + accessPathSuggestions.parseResults( |
| 528 | + results, |
| 529 | + modelsAsDataLanguage, |
| 530 | + this.app.logger, |
| 531 | + ), |
| 532 | + cliServer: this.cliServer, |
| 533 | + queryRunner: this.queryRunner, |
| 534 | + queryStorageDir: this.queryStorageDir, |
| 535 | + databaseItem: this.databaseItem, |
| 536 | + progress, |
| 537 | + token: tokenSource.token, |
| 538 | + logger: this.app.logger, |
| 539 | + }); |
| 540 | + |
| 541 | + if (!suggestions) { |
| 542 | + return; |
| 543 | + } |
| 544 | + |
| 545 | + const options: AccessPathSuggestionOptions = { |
| 546 | + input: parseAccessPathSuggestionRowsToOptions(suggestions.input), |
| 547 | + output: parseAccessPathSuggestionRowsToOptions(suggestions.output), |
| 548 | + }; |
| 549 | + |
| 550 | + await this.postMessage({ |
| 551 | + t: "setAccessPathSuggestions", |
| 552 | + accessPathSuggestions: options, |
| 553 | + }); |
| 554 | + } catch (e: unknown) { |
| 555 | + void showAndLogExceptionWithTelemetry( |
| 556 | + this.app.logger, |
| 557 | + this.app.telemetry, |
| 558 | + redactableError( |
| 559 | + asError(e), |
| 560 | + )`Failed to fetch access path suggestions: ${getErrorMessage(e)}`, |
| 561 | + ); |
| 562 | + } |
| 563 | + } |
| 564 | + |
488 | 565 | protected async generateModeledMethods(): Promise<void> { |
489 | 566 | await withProgress( |
490 | 567 | async (progress) => { |
|
0 commit comments