1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.LanguageServerLoadingHandler = void 0;
|
4 | const vscode_languageserver_1 = require("vscode-languageserver");
|
5 | class LanguageServerLoadingHandler {
|
6 | constructor(connection) {
|
7 | this.connection = connection;
|
8 | this.latestLoadingToken = 0;
|
9 | }
|
10 | async handle(message, value) {
|
11 | const token = this.latestLoadingToken;
|
12 | this.latestLoadingToken += 1;
|
13 | this.connection.sendNotification(new vscode_languageserver_1.NotificationType("apollographql/loading"), { message, token });
|
14 | try {
|
15 | const ret = await value;
|
16 | this.connection.sendNotification(new vscode_languageserver_1.NotificationType("apollographql/loadingComplete"), token);
|
17 | return ret;
|
18 | }
|
19 | catch (e) {
|
20 | this.connection.sendNotification(new vscode_languageserver_1.NotificationType("apollographql/loadingComplete"), token);
|
21 | this.showError(`Error in "${message}": ${e}`);
|
22 | throw e;
|
23 | }
|
24 | }
|
25 | handleSync(message, value) {
|
26 | const token = this.latestLoadingToken;
|
27 | this.latestLoadingToken += 1;
|
28 | this.connection.sendNotification(new vscode_languageserver_1.NotificationType("apollographql/loading"), { message, token });
|
29 | try {
|
30 | const ret = value();
|
31 | this.connection.sendNotification(new vscode_languageserver_1.NotificationType("apollographql/loadingComplete"), token);
|
32 | return ret;
|
33 | }
|
34 | catch (e) {
|
35 | this.connection.sendNotification(new vscode_languageserver_1.NotificationType("apollographql/loadingComplete"), token);
|
36 | this.showError(`Error in "${message}": ${e}`);
|
37 | throw e;
|
38 | }
|
39 | }
|
40 | showError(message) {
|
41 | this.connection.window.showErrorMessage(message);
|
42 | }
|
43 | }
|
44 | exports.LanguageServerLoadingHandler = LanguageServerLoadingHandler;
|
45 |
|
\ | No newline at end of file |