@codingame/monaco-languageclient-wrapper 1.1.8 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { MonacoLanguageClient, Emitter, Event, TextDocument } from '@codingame/monaco-languageclient';
1
+ import { MonacoLanguageClient, Emitter, Event, TextDocument, ProtocolNotificationType } from '@codingame/monaco-languageclient';
2
2
  import { LanguageClientId, StaticLanguageClientOptions } from './staticOptions';
3
3
  declare type Status = {
4
4
  type: string;
@@ -11,6 +11,10 @@ export interface LanguageClient {
11
11
  export interface StatusChangeEvent {
12
12
  status: Status;
13
13
  }
14
+ export interface WillShutdownParams {
15
+ delay: number;
16
+ }
17
+ export declare const willShutdownNotificationType: ProtocolNotificationType<WillShutdownParams, void>;
14
18
  export declare class LanguageClientManager implements LanguageClient {
15
19
  private id;
16
20
  private sessionId;
@@ -22,6 +26,7 @@ export declare class LanguageClientManager implements LanguageClient {
22
26
  protected readonly onDidChangeStatusEmitter: Emitter<StatusChangeEvent>;
23
27
  protected readonly onErrorEmitter: Emitter<Error>;
24
28
  protected readonly onWillCloseEmitter: Emitter<void>;
29
+ protected readonly onWillShutdownEmitter: Emitter<WillShutdownParams>;
25
30
  protected currentStatus?: Status;
26
31
  constructor(id: LanguageClientId, sessionId: string | undefined, languageServerAddress: string, getSecurityToken: () => Promise<string>, languageServerOptions: StaticLanguageClientOptions, libraryUrls: string[]);
27
32
  private updateStatus;
@@ -30,6 +35,7 @@ export declare class LanguageClientManager implements LanguageClient {
30
35
  dispose(): Promise<void>;
31
36
  get onDidChangeStatus(): Event<StatusChangeEvent>;
32
37
  get onWillClose(): Event<void>;
38
+ get onWillShutdown(): Event<WillShutdownParams>;
33
39
  get onError(): Event<Error>;
34
40
  isModelManaged(document: TextDocument): boolean;
35
41
  isDisposed(): boolean;
package/dist/main.js CHANGED
@@ -20732,8 +20732,7 @@ async function openConnection(url, errorHandler, closeHandler) {
20732
20732
  webSocketConnection.onDispose(() => {
20733
20733
  webSocket.close();
20734
20734
  });
20735
- const onceCloseHandler = once(closeHandler);
20736
- const connection = lib$1.createConnection(webSocketConnection, errorHandler, onceCloseHandler);
20735
+ const connection = lib$1.createConnection(webSocketConnection, errorHandler, closeHandler);
20737
20736
  const existingRegistrations = new Set();
20738
20737
 
20739
20738
  const fixedConnection = _objectSpread2(_objectSpread2({}, connection), {}, {
@@ -20802,13 +20801,13 @@ async function openConnection(url, errorHandler, closeHandler) {
20802
20801
  // The language client is then still active but without a proper connection and errors will occurs
20803
20802
 
20804
20803
 
20805
- onceCloseHandler();
20804
+ closeHandler();
20806
20805
  },
20807
20806
  shutdown: async () => {
20808
20807
  // The shutdown should NEVER fail or the connection is not closed and the lsp client is not properly cleaned
20809
20808
  // see https://github.com/microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L3103
20810
20809
  try {
20811
- await connection.exit();
20810
+ await connection.shutdown();
20812
20811
  } catch (error) {
20813
20812
  console.warn('[LSP]', 'Error while shutdown lsp', error);
20814
20813
  }
@@ -20836,15 +20835,20 @@ class CGLSPConnectionProvider {
20836
20835
  }
20837
20836
 
20838
20837
  async get(errorHandler, closeHandler) {
20838
+ const onceDelayedCloseHandler = once(() => {
20839
+ setTimeout(() => {
20840
+ closeHandler();
20841
+ }, RETRY_DELAY);
20842
+ });
20843
+
20839
20844
  try {
20840
20845
  const path = this.sessionId != null ? "run/".concat(this.sessionId, "/").concat(this.id) : "run/".concat(this.id);
20841
20846
  const url = new URL(path, this.serverAddress);
20842
20847
  this.libraryUrls.forEach(libraryUrl => url.searchParams.append('libraryUrl', libraryUrl));
20843
20848
  url.searchParams.append('token', await this.getSecurityToken());
20844
- return await openConnection(url, errorHandler, closeHandler);
20849
+ return await openConnection(url, errorHandler, onceDelayedCloseHandler);
20845
20850
  } catch (err) {
20846
- setTimeout(closeHandler, RETRY_DELAY);
20847
- await delay$1(1000);
20851
+ onceDelayedCloseHandler();
20848
20852
  throw err;
20849
20853
  }
20850
20854
  }
@@ -21092,7 +21096,14 @@ const staticOptions = asLanguageClientOptionsById({
21092
21096
  sql: {
21093
21097
  documentSelector: [{
21094
21098
  language: 'sql'
21095
- }]
21099
+ }],
21100
+ // Disable code actions
21101
+ middleware: {
21102
+ provideCodeActions() {
21103
+ return [];
21104
+ }
21105
+
21106
+ }
21096
21107
  },
21097
21108
  swift: {
21098
21109
  // https://github.com/apple/sourcekit-lsp/blob/59b5e68f7f8408b5bc44bd47f71ef1afdc63e7a6/Editors/vscode/src/extension.ts#L22
@@ -21115,6 +21126,7 @@ const staticOptions = asLanguageClientOptionsById({
21115
21126
  }
21116
21127
  });
21117
21128
 
21129
+ const willShutdownNotificationType = new lib$1.ProtocolNotificationType('willShutdown');
21118
21130
  class LanguageClientManager {
21119
21131
  constructor(id, sessionId, languageServerAddress, getSecurityToken, languageServerOptions, libraryUrls) {
21120
21132
  this.id = id;
@@ -21132,6 +21144,8 @@ class LanguageClientManager {
21132
21144
 
21133
21145
  _defineProperty(this, "onWillCloseEmitter", new lib$1.Emitter());
21134
21146
 
21147
+ _defineProperty(this, "onWillShutdownEmitter", new lib$1.Emitter());
21148
+
21135
21149
  _defineProperty(this, "currentStatus", void 0);
21136
21150
 
21137
21151
  _defineProperty(this, "handleClose", () => {
@@ -21189,6 +21203,10 @@ class LanguageClientManager {
21189
21203
  return this.onWillCloseEmitter.event;
21190
21204
  }
21191
21205
 
21206
+ get onWillShutdown() {
21207
+ return this.onWillShutdownEmitter.event;
21208
+ }
21209
+
21192
21210
  get onError() {
21193
21211
  return this.onErrorEmitter.event;
21194
21212
  }
@@ -21206,38 +21224,71 @@ class LanguageClientManager {
21206
21224
  }
21207
21225
 
21208
21226
  start() {
21227
+ var _this$languageServerO;
21228
+
21209
21229
  const onServerResponse = new lib$1.Emitter();
21210
21230
  const languageClient = createLanguageClient(this.id, this.sessionId, this.languageServerOptions, this.languageServerAddress, this.getSecurityToken, this.libraryUrls, {
21211
21231
  error: this.handleError,
21212
21232
  closed: this.handleClose
21213
- }, {
21233
+ }, _objectSpread2(_objectSpread2({}, (_this$languageServerO = this.languageServerOptions.middleware) !== null && _this$languageServerO !== void 0 ? _this$languageServerO : {}), {}, {
21214
21234
  handleDiagnostics: (uri, diagnostics, next) => {
21215
- next(uri, diagnostics);
21235
+ var _this$languageServerO2;
21236
+
21237
+ if (((_this$languageServerO2 = this.languageServerOptions.middleware) === null || _this$languageServerO2 === void 0 ? void 0 : _this$languageServerO2.handleDiagnostics) != null) {
21238
+ this.languageServerOptions.middleware.handleDiagnostics(uri, diagnostics, next);
21239
+ } else {
21240
+ next(uri, diagnostics);
21241
+ }
21242
+
21216
21243
  onServerResponse.fire();
21217
21244
  },
21218
21245
  provideCodeActions: async (document, range, context, token, next) => {
21219
21246
  try {
21220
- return await next(document, range, context, token);
21247
+ var _this$languageServerO3;
21248
+
21249
+ if (((_this$languageServerO3 = this.languageServerOptions.middleware) === null || _this$languageServerO3 === void 0 ? void 0 : _this$languageServerO3.provideCodeActions) != null) {
21250
+ return await this.languageServerOptions.middleware.provideCodeActions(document, range, context, token, next);
21251
+ } else {
21252
+ return await next(document, range, context, token);
21253
+ }
21221
21254
  } finally {
21222
21255
  onServerResponse.fire();
21223
21256
  }
21224
21257
  },
21225
21258
  provideDocumentRangeSemanticTokens: async (document, range, token, next) => {
21226
21259
  try {
21227
- return await next(document, range, token);
21260
+ var _this$languageServerO4;
21261
+
21262
+ if (((_this$languageServerO4 = this.languageServerOptions.middleware) === null || _this$languageServerO4 === void 0 ? void 0 : _this$languageServerO4.provideDocumentRangeSemanticTokens) != null) {
21263
+ return await this.languageServerOptions.middleware.provideDocumentRangeSemanticTokens(document, range, token, next);
21264
+ } else {
21265
+ return await next(document, range, token);
21266
+ }
21228
21267
  } finally {
21229
21268
  onServerResponse.fire();
21230
21269
  }
21231
21270
  },
21232
21271
  provideDocumentSemanticTokens: async (document, token, next) => {
21233
21272
  try {
21234
- return await next(document, token);
21273
+ var _this$languageServerO5;
21274
+
21275
+ if (((_this$languageServerO5 = this.languageServerOptions.middleware) === null || _this$languageServerO5 === void 0 ? void 0 : _this$languageServerO5.provideDocumentSemanticTokens) != null) {
21276
+ return await this.languageServerOptions.middleware.provideDocumentSemanticTokens(document, token, next);
21277
+ } else {
21278
+ return await next(document, token);
21279
+ }
21235
21280
  } finally {
21236
21281
  onServerResponse.fire();
21237
21282
  }
21238
21283
  },
21239
21284
  handleWorkDoneProgress: async (token, params, next) => {
21240
- next(token, params);
21285
+ var _this$languageServerO6;
21286
+
21287
+ if (((_this$languageServerO6 = this.languageServerOptions.middleware) === null || _this$languageServerO6 === void 0 ? void 0 : _this$languageServerO6.handleWorkDoneProgress) != null) {
21288
+ this.languageServerOptions.middleware.handleWorkDoneProgress(token, params, next);
21289
+ } else {
21290
+ next(token, params);
21291
+ }
21241
21292
 
21242
21293
  if (params.kind === 'end') {
21243
21294
  onServerResponse.fire();
@@ -21245,12 +21296,18 @@ class LanguageClientManager {
21245
21296
  },
21246
21297
  provideHover: async (document, position, token, next) => {
21247
21298
  try {
21248
- return await next(document, position, token);
21299
+ var _this$languageServerO7;
21300
+
21301
+ if (((_this$languageServerO7 = this.languageServerOptions.middleware) === null || _this$languageServerO7 === void 0 ? void 0 : _this$languageServerO7.provideHover) != null) {
21302
+ return await this.languageServerOptions.middleware.provideHover(document, position, token, next);
21303
+ } else {
21304
+ return await next(document, position, token);
21305
+ }
21249
21306
  } finally {
21250
21307
  onServerResponse.fire();
21251
21308
  }
21252
21309
  }
21253
- });
21310
+ }));
21254
21311
  this.languageClient = languageClient;
21255
21312
  let readyPromise = null;
21256
21313
  languageClient.onDidChangeState(async state => {
@@ -21297,6 +21354,9 @@ class LanguageClientManager {
21297
21354
  }
21298
21355
  }
21299
21356
  });
21357
+ this.languageClient.onNotification(willShutdownNotificationType, params => {
21358
+ this.onWillShutdownEmitter.fire(params);
21359
+ });
21300
21360
  this.languageClient.start();
21301
21361
  }
21302
21362