@difizen/libro-lsp 0.1.2

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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/adapters/adapter.d.ts +255 -0
  4. package/es/adapters/adapter.d.ts.map +1 -0
  5. package/es/adapters/adapter.js +647 -0
  6. package/es/adapters/notebook-adapter.d.ts +150 -0
  7. package/es/adapters/notebook-adapter.d.ts.map +1 -0
  8. package/es/adapters/notebook-adapter.js +588 -0
  9. package/es/adapters/status-message.d.ts +48 -0
  10. package/es/adapters/status-message.d.ts.map +1 -0
  11. package/es/adapters/status-message.js +110 -0
  12. package/es/connection-manager.d.ts +199 -0
  13. package/es/connection-manager.d.ts.map +1 -0
  14. package/es/connection-manager.js +685 -0
  15. package/es/connection.d.ts +149 -0
  16. package/es/connection.d.ts.map +1 -0
  17. package/es/connection.js +591 -0
  18. package/es/extractors/index.d.ts +4 -0
  19. package/es/extractors/index.d.ts.map +1 -0
  20. package/es/extractors/index.js +6 -0
  21. package/es/extractors/manager.d.ts +31 -0
  22. package/es/extractors/manager.d.ts.map +1 -0
  23. package/es/extractors/manager.js +90 -0
  24. package/es/extractors/text-extractor.d.ts +56 -0
  25. package/es/extractors/text-extractor.d.ts.map +1 -0
  26. package/es/extractors/text-extractor.js +72 -0
  27. package/es/extractors/types.d.ts +68 -0
  28. package/es/extractors/types.d.ts.map +1 -0
  29. package/es/extractors/types.js +1 -0
  30. package/es/feature.d.ts +29 -0
  31. package/es/feature.d.ts.map +1 -0
  32. package/es/feature.js +85 -0
  33. package/es/index.d.ts +19 -0
  34. package/es/index.d.ts.map +1 -0
  35. package/es/index.js +21 -0
  36. package/es/lsp-app-contribution.d.ts +19 -0
  37. package/es/lsp-app-contribution.d.ts.map +1 -0
  38. package/es/lsp-app-contribution.js +155 -0
  39. package/es/lsp-protocol.d.ts +10 -0
  40. package/es/lsp-protocol.d.ts.map +1 -0
  41. package/es/lsp-protocol.js +1 -0
  42. package/es/lsp.d.ts +136 -0
  43. package/es/lsp.d.ts.map +1 -0
  44. package/es/lsp.js +141 -0
  45. package/es/manager.d.ts +142 -0
  46. package/es/manager.d.ts.map +1 -0
  47. package/es/manager.js +423 -0
  48. package/es/module.d.ts +3 -0
  49. package/es/module.d.ts.map +1 -0
  50. package/es/module.js +21 -0
  51. package/es/plugin.d.ts +56 -0
  52. package/es/plugin.d.ts.map +1 -0
  53. package/es/plugin.js +0 -0
  54. package/es/positioning.d.ts +66 -0
  55. package/es/positioning.d.ts.map +1 -0
  56. package/es/positioning.js +96 -0
  57. package/es/schema.d.ts +240 -0
  58. package/es/schema.d.ts.map +1 -0
  59. package/es/schema.js +0 -0
  60. package/es/tokens.d.ts +677 -0
  61. package/es/tokens.d.ts.map +1 -0
  62. package/es/tokens.js +183 -0
  63. package/es/utils.d.ts +33 -0
  64. package/es/utils.d.ts.map +1 -0
  65. package/es/utils.js +168 -0
  66. package/es/virtual/document.d.ts +546 -0
  67. package/es/virtual/document.d.ts.map +1 -0
  68. package/es/virtual/document.js +1263 -0
  69. package/es/ws-connection/server-capability-registration.d.ts +19 -0
  70. package/es/ws-connection/server-capability-registration.d.ts.map +1 -0
  71. package/es/ws-connection/server-capability-registration.js +51 -0
  72. package/es/ws-connection/types.d.ts +76 -0
  73. package/es/ws-connection/types.d.ts.map +1 -0
  74. package/es/ws-connection/types.js +1 -0
  75. package/es/ws-connection/ws-connection.d.ts +105 -0
  76. package/es/ws-connection/ws-connection.d.ts.map +1 -0
  77. package/es/ws-connection/ws-connection.js +301 -0
  78. package/package.json +67 -0
  79. package/src/adapters/adapter.ts +611 -0
  80. package/src/adapters/notebook-adapter.ts +463 -0
  81. package/src/adapters/status-message.ts +93 -0
  82. package/src/connection-manager.ts +626 -0
  83. package/src/connection.ts +570 -0
  84. package/src/extractors/index.ts +6 -0
  85. package/src/extractors/manager.ts +82 -0
  86. package/src/extractors/text-extractor.ts +94 -0
  87. package/src/extractors/types.ts +78 -0
  88. package/src/feature.ts +60 -0
  89. package/src/index.spec.ts +10 -0
  90. package/src/index.ts +21 -0
  91. package/src/lsp-app-contribution.ts +83 -0
  92. package/src/lsp-protocol.ts +10 -0
  93. package/src/lsp.ts +160 -0
  94. package/src/manager.ts +358 -0
  95. package/src/module.ts +32 -0
  96. package/src/plugin.ts +62 -0
  97. package/src/positioning.ts +121 -0
  98. package/src/schema.ts +249 -0
  99. package/src/tokens.ts +843 -0
  100. package/src/utils.ts +109 -0
  101. package/src/virtual/document.ts +1250 -0
  102. package/src/ws-connection/server-capability-registration.ts +77 -0
  103. package/src/ws-connection/types.ts +102 -0
  104. package/src/ws-connection/ws-connection.ts +320 -0
package/src/tokens.ts ADDED
@@ -0,0 +1,843 @@
1
+ /* eslint-disable @typescript-eslint/no-namespace */
2
+ // Copyright (c) Jupyter Development Team.
3
+ // Distributed under the terms of the Modified BSD License.
4
+
5
+ // import type { ServerConnection } from '@jupyterlab/services';
6
+
7
+ import type { IEditor as ICodeEditor } from '@difizen/libro-code-editor';
8
+ import type { NotebookView } from '@difizen/libro-core';
9
+ import type { Disposable, Emitter, Event } from '@difizen/mana-app';
10
+ import type * as rpc from 'vscode-jsonrpc';
11
+ import type * as lsp from 'vscode-languageserver-protocol';
12
+
13
+ import type { WidgetLSPAdapter } from './adapters/adapter.js';
14
+ import type { IForeignCodeExtractor } from './extractors/types.js';
15
+ import type {
16
+ AnyCompletion,
17
+ AnyLocation,
18
+ ClientCapabilities,
19
+ LanguageIdentifier,
20
+ } from './lsp.js';
21
+ import type { LanguageServer1 as LSPLanguageServerSettings } from './plugin.js';
22
+ import type * as SCHEMA from './schema.js';
23
+ import type { VirtualDocument } from './virtual/document.js';
24
+ import type {
25
+ IDocumentInfo,
26
+ ILspConnection,
27
+ ILspOptions,
28
+ } from './ws-connection/types.js';
29
+
30
+ export { IDocumentInfo };
31
+
32
+ /**
33
+ * Example server keys==ids that are expected. The list is not exhaustive.
34
+ * Custom server keys are allowed. Constraining the values helps avoid errors,
35
+ * but at runtime any value is allowed.
36
+ */
37
+ export type TLanguageServerId =
38
+ | 'pyright-extended'
39
+ | 'pyright'
40
+ | 'pylsp'
41
+ | 'bash-language-server'
42
+ | 'dockerfile-language-server-nodejs'
43
+ | 'javascript-typescript-langserver'
44
+ | 'unified-language-server'
45
+ | 'vscode-css-languageserver-bin'
46
+ | 'vscode-html-languageserver-bin'
47
+ | 'vscode-json-languageserver-bin'
48
+ | 'yaml-language-server'
49
+ | 'r-languageserver';
50
+
51
+ /**
52
+ * Type alias for the server ids.
53
+ */
54
+ export type TServerKeys = TLanguageServerId;
55
+
56
+ /**
57
+ * Type of language server configuration, it is a map between server
58
+ * id and its setting.
59
+ */
60
+ export type TLanguageServerConfigurations = Partial<
61
+ Record<TServerKeys, LSPLanguageServerSettings>
62
+ >;
63
+
64
+ /**
65
+ * Type of language server session, it is a map between server
66
+ * id and the associated session.
67
+ */
68
+ export type TSessionMap = Map<TServerKeys, SCHEMA.LanguageServerSession>;
69
+
70
+ /**
71
+ * Type of language server specs, it is a map between server
72
+ * id and the associated specs.
73
+ */
74
+ export type TSpecsMap = Map<TServerKeys, SCHEMA.LanguageServerSpec>;
75
+
76
+ /**
77
+ * Type alias for language server id, it helps to clarify other types.
78
+ */
79
+ export type TLanguageId = string;
80
+
81
+ // export const ILanguageServerManager = Symbol('ILanguageServerManager');
82
+
83
+ export interface ILanguageServerManager extends Disposable {
84
+ /**
85
+ * @alpha
86
+ *
87
+ * Signal emitted when the language server sessions are changed.
88
+ */
89
+ sessionsChanged: Event<void>;
90
+
91
+ /**
92
+ * @alpha
93
+ *
94
+ * The current session information of running language servers.
95
+ */
96
+ readonly sessions: TSessionMap;
97
+
98
+ /**
99
+ * @alpha
100
+ *
101
+ * A promise that is fulfilled when the connection manager is ready.
102
+ */
103
+ readonly ready: Promise<void>;
104
+
105
+ /**
106
+ * @alpha
107
+ *
108
+ * Current endpoint to get the status of running language servers
109
+ */
110
+ readonly statusUrl: string;
111
+
112
+ /**
113
+ * @alpha
114
+ *
115
+ * Status code of the `fetchSession` request.
116
+ */
117
+ readonly statusCode: number;
118
+
119
+ /**
120
+ * @alpha
121
+ *
122
+ * Check if the manager is enabled or disabled
123
+ */
124
+ readonly isEnabled: boolean;
125
+
126
+ /**
127
+ * @alpha
128
+ *
129
+ * Enable the language server services
130
+ */
131
+ enable(): void;
132
+
133
+ /**
134
+ * @alpha
135
+ *
136
+ * Disable the language server services
137
+ */
138
+ disable(): void;
139
+
140
+ /**
141
+ * @alpha
142
+ *
143
+ * An ordered list of matching >running< sessions, with servers of higher rank higher in the list
144
+ */
145
+ getMatchingServers(options: IGetServerIdOptions): TLanguageServerId[];
146
+
147
+ /**
148
+ * @alpha
149
+ *
150
+ * A list of all known matching specs (whether detected or not).
151
+ */
152
+ getMatchingSpecs(options: IGetServerIdOptions): TSpecsMap;
153
+
154
+ /**
155
+ * @alpha
156
+ *
157
+ * Set the configuration for language servers
158
+ */
159
+ setConfiguration(configuration: TLanguageServerConfigurations): void;
160
+
161
+ /**
162
+ * @alpha
163
+ *
164
+ * Send a request to language server handler to get the session information.
165
+ */
166
+ fetchSessions(): Promise<void>;
167
+ }
168
+
169
+ /**
170
+ * Virtual document namespace
171
+ */
172
+ export namespace Document {
173
+ /**
174
+ * Code block description.
175
+ */
176
+ export interface ICodeBlockOptions {
177
+ /**
178
+ * CodeEditor accessor
179
+ */
180
+ ceEditor: IEditor;
181
+
182
+ /**
183
+ * Type of the cell holding this block
184
+ */
185
+ type: string;
186
+
187
+ /**
188
+ * Editor text
189
+ *
190
+ * #### Notes
191
+ * This must always be available and should come from the document model directly.
192
+ */
193
+ value: string;
194
+ }
195
+
196
+ /**
197
+ * Code editor accessor.
198
+ */
199
+ export interface IEditor {
200
+ /**
201
+ * CodeEditor getter.
202
+ *
203
+ * It will return `null` if the editor is not yet instantiated;
204
+ * e.g. to support windowed notebook.
205
+ */
206
+ getEditor(): ICodeEditor | null;
207
+
208
+ /**
209
+ * Promise getter that resolved when the editor is instantiated.
210
+ */
211
+ ready(): Promise<ICodeEditor>;
212
+
213
+ /**
214
+ * Reveal the code editor in viewport.
215
+ *
216
+ * ### Notes
217
+ * The promise will resolve when the editor is instantiated and in
218
+ * the viewport.
219
+ */
220
+ reveal(): Promise<ICodeEditor>;
221
+ }
222
+
223
+ /**
224
+ * Foreign context within code block.
225
+ */
226
+ export interface IForeignContext {
227
+ /**
228
+ * The virtual document
229
+ */
230
+ foreignDocument: VirtualDocument;
231
+
232
+ /**
233
+ * The document holding the virtual document.
234
+ */
235
+ parentHost: VirtualDocument;
236
+ }
237
+
238
+ /**
239
+ * Virtual document block.
240
+ */
241
+ export interface IVirtualDocumentBlock {
242
+ /**
243
+ * Line corresponding to the block in the entire foreign document
244
+ */
245
+ virtualLine: number;
246
+
247
+ /**
248
+ * The virtual document holding this virtual line.
249
+ */
250
+ virtualDocument: VirtualDocument;
251
+
252
+ /**
253
+ * The CM editor associated with this virtual line.
254
+ */
255
+ editor: IEditor;
256
+ }
257
+ }
258
+
259
+ /**
260
+ * LSP endpoint prefix.
261
+ */
262
+ export const URL_NS = 'lsp';
263
+
264
+ export const ILanguageServerManagerFactory = Symbol('ILanguageServerManagerFactory');
265
+
266
+ export type ILanguageServerManagerFactory = (
267
+ option: ILanguageServerManagerOptions,
268
+ ) => ILanguageServerManager;
269
+
270
+ export const ILanguageServerManagerOptions = Symbol('ILanguageServerManagerOptions');
271
+
272
+ export interface ILanguageServerManagerOptions {
273
+ /**
274
+ * The Jupyter server settings objec
275
+ */
276
+ // settings?: ServerConnection.ISettings;
277
+
278
+ /**
279
+ * Base URL of current JupyterLab server.
280
+ */
281
+ baseUrl?: string;
282
+
283
+ /**
284
+ * Number of connection retries to fetch the sessions.
285
+ * Default 2.
286
+ */
287
+ retries?: number;
288
+
289
+ /**
290
+ * The interval for retries, default 10 seconds.
291
+ */
292
+ retriesInterval?: number;
293
+ }
294
+ /**
295
+ * The argument for getting server session or specs.
296
+ */
297
+ export interface IGetServerIdOptions {
298
+ /**
299
+ * Language server id
300
+ */
301
+ language?: TLanguageId;
302
+
303
+ /**
304
+ * Server specs mime type.
305
+ */
306
+ mimeType?: string;
307
+ }
308
+
309
+ /**
310
+ * Option to create the websocket connection to the LSP proxy server
311
+ * on the backend.
312
+ */
313
+ export interface ISocketConnectionOptions {
314
+ /**
315
+ * The virtual document trying to connect to the LSP server.
316
+ */
317
+ virtualDocument: VirtualDocument;
318
+
319
+ /**
320
+ * The language identifier, corresponding to the API endpoint on the
321
+ * LSP proxy server.
322
+ */
323
+ language: string;
324
+
325
+ /**
326
+ * LSP capabilities describing currently supported features
327
+ */
328
+ capabilities: ClientCapabilities;
329
+
330
+ /**
331
+ * Is the file format is supported by LSP?
332
+ */
333
+ hasLspSupportedFile: boolean;
334
+ }
335
+
336
+ /**
337
+ * @alpha
338
+ *
339
+ * Interface describing the LSP connection state
340
+ */
341
+ export interface IDocumentConnectionData {
342
+ /**
343
+ * The virtual document connected to the language server
344
+ */
345
+ virtualDocument: VirtualDocument;
346
+ /**
347
+ * The connection between the virtual document and the language server.
348
+ */
349
+ connection: ILSPConnection;
350
+ }
351
+
352
+ export const ILSPDocumentConnectionManager = Symbol('ILSPDocumentConnectionManager');
353
+
354
+ /**
355
+ * @alpha
356
+ *
357
+ * The LSP connection state manager
358
+ */
359
+ export interface ILSPDocumentConnectionManager {
360
+ /**
361
+ * The mapping of document uri to the connection to language server.
362
+ */
363
+ connections: Map<VirtualDocument.uri, ILSPConnection>;
364
+
365
+ /**
366
+ * The mapping of document uri to the virtual document.
367
+ */
368
+ documents: Map<VirtualDocument.uri, VirtualDocument>;
369
+
370
+ /**
371
+ * The mapping of document uri to the widget adapter.
372
+ */
373
+ adapters: Map<string, WidgetLSPAdapter<NotebookView>>;
374
+
375
+ /**
376
+ * Signal emitted when a connection is connected.
377
+ */
378
+ connected: Event<IDocumentConnectionData>;
379
+
380
+ /**
381
+ * Signal emitted when a connection is disconnected.
382
+ */
383
+ disconnected: Event<IDocumentConnectionData>;
384
+
385
+ /**
386
+ * Signal emitted when the language server is initialized.
387
+ */
388
+ initialized: Event<IDocumentConnectionData>;
389
+
390
+ /**
391
+ * Signal emitted when a virtual document is closed.
392
+ */
393
+ closed: Event<IDocumentConnectionData>;
394
+
395
+ /**
396
+ * Signal emitted when the content of a virtual document is changed.
397
+ */
398
+ documentsChanged: Event<Map<VirtualDocument.uri, VirtualDocument>>;
399
+
400
+ /**
401
+ * The language server manager instance.
402
+ */
403
+ languageServerManager: ILanguageServerManager;
404
+
405
+ /**
406
+ * A promise that is fulfilled when the connection manager is ready.
407
+ */
408
+ readonly ready: Promise<void>;
409
+
410
+ /**
411
+ * Handles the settings that do not require an existing connection
412
+ * with a language server (or can influence to which server the
413
+ * connection will be created, e.g. `rank`).
414
+ *
415
+ * This function should be called **before** initialization of servers.
416
+ */
417
+ updateConfiguration(allServerSettings: TLanguageServerConfigurations): void;
418
+
419
+ /**
420
+ * Handles the settings that the language servers accept using
421
+ * `onDidChangeConfiguration` messages, which should be passed under
422
+ * the "serverSettings" keyword in the setting registry.
423
+ * Other configuration options are handled by `updateConfiguration` instead.
424
+ *
425
+ * This function should be called **after** initialization of servers.
426
+ */
427
+ updateServerConfigurations(allServerSettings: TLanguageServerConfigurations): void;
428
+
429
+ /**
430
+ * Retry to connect to the server each `reconnectDelay` seconds
431
+ * and for `retrialsLeft` times.
432
+ */
433
+ retryToConnect(
434
+ options: ISocketConnectionOptions,
435
+ reconnectDelay: number,
436
+ retrialsLeft: number,
437
+ ): Promise<void>;
438
+
439
+ /**
440
+ * Create a new connection to the language server
441
+ * @return A promise of the LSP connection
442
+ */
443
+ connect(
444
+ options: ISocketConnectionOptions,
445
+ firstTimeoutSeconds?: number,
446
+ secondTimeoutMinute?: number,
447
+ ): Promise<ILSPConnection | undefined>;
448
+
449
+ /**
450
+ * Disconnect the connection to the language server of the requested
451
+ * language.
452
+ */
453
+ disconnect(languageId: TLanguageServerId): void;
454
+
455
+ /**
456
+ * Disconnect the signals of requested virtual document uri.
457
+ */
458
+ unregisterDocument(uri: string): void;
459
+
460
+ /**
461
+ * Register a widget adapter.
462
+ *
463
+ * @param path - path to current document widget of input adapter
464
+ * @param adapter - the adapter need to be registered
465
+ */
466
+ registerAdapter(path: string, adapter: WidgetLSPAdapter<NotebookView>): void;
467
+ }
468
+
469
+ /**
470
+ * @alpha
471
+ *
472
+ * Interface describing the client feature
473
+ */
474
+ export interface IFeature {
475
+ /**
476
+ * The feature identifier. It must be the same as the feature plugin id.
477
+ */
478
+ id: string;
479
+
480
+ /**
481
+ * LSP capabilities implemented by the feature.
482
+ */
483
+ capabilities?: ClientCapabilities;
484
+ }
485
+
486
+ export const ILSPFeatureManager = Symbol('ILSPFeatureManager');
487
+
488
+ /**
489
+ * @alpha
490
+ *
491
+ * The LSP feature manager
492
+ */
493
+ export interface ILSPFeatureManager {
494
+ /**
495
+ * A read-only registry of all registered features.
496
+ */
497
+ readonly features: IFeature[];
498
+
499
+ /**
500
+ * Register the new feature (frontend capability)
501
+ * for one or more code editor implementations.
502
+ */
503
+ register(feature: IFeature): void;
504
+
505
+ /**
506
+ * Signal emitted when a feature is registered
507
+ */
508
+ featuresRegistered: Event<IFeature>;
509
+
510
+ /**
511
+ * Get capabilities of all registered features
512
+ */
513
+ clientCapabilities(): ClientCapabilities;
514
+ }
515
+
516
+ export const ILSPCodeExtractorsManager = Symbol('ILSPCodeExtractorsManager');
517
+
518
+ /**
519
+ * @alpha
520
+ *
521
+ * Manages code transclusion plugins.
522
+ */
523
+ export interface ILSPCodeExtractorsManager {
524
+ /**
525
+ * Get the foreign code extractors.
526
+ */
527
+ getExtractors(cellType: string, hostLanguage: string | null): IForeignCodeExtractor[];
528
+
529
+ /**
530
+ * Register the extraction rules to be applied in documents with language `host_language`.
531
+ */
532
+ register(
533
+ extractor: IForeignCodeExtractor,
534
+ hostLanguage: LanguageIdentifier | null,
535
+ ): void;
536
+ }
537
+
538
+ /**
539
+ * Argument for creating a connection to the LSP proxy server.
540
+ */
541
+ export interface ILSPOptions extends ILspOptions {
542
+ /**
543
+ * Client capabilities implemented by the client.
544
+ */
545
+ capabilities: ClientCapabilities;
546
+
547
+ /**
548
+ * Language server id.
549
+ */
550
+ serverIdentifier?: string;
551
+ }
552
+
553
+ /**
554
+ * Method strings are reproduced here because a non-typing import of
555
+ * `vscode-languageserver-protocol` is ridiculously expensive.
556
+ */
557
+ export namespace Method {
558
+ /** Server notifications */
559
+ export enum ServerNotification {
560
+ PUBLISH_DIAGNOSTICS = 'textDocument/publishDiagnostics',
561
+ SHOW_MESSAGE = 'window/showMessage',
562
+ LOG_TRACE = '$/logTrace',
563
+ LOG_MESSAGE = 'window/logMessage',
564
+ }
565
+
566
+ /** Client notifications */
567
+ export enum ClientNotification {
568
+ DID_CHANGE = 'textDocument/didChange',
569
+ DID_CHANGE_CONFIGURATION = 'workspace/didChangeConfiguration',
570
+ DID_OPEN = 'textDocument/didOpen',
571
+ DID_SAVE = 'textDocument/didSave',
572
+ INITIALIZED = 'initialized',
573
+ SET_TRACE = '$/setTrace',
574
+ }
575
+
576
+ /** Server requests */
577
+ export enum ServerRequest {
578
+ REGISTER_CAPABILITY = 'client/registerCapability',
579
+ SHOW_MESSAGE_REQUEST = 'window/showMessageRequest',
580
+ UNREGISTER_CAPABILITY = 'client/unregisterCapability',
581
+ WORKSPACE_CONFIGURATION = 'workspace/configuration',
582
+ }
583
+
584
+ /** Client requests */
585
+ export enum ClientRequest {
586
+ COMPLETION = 'textDocument/completion',
587
+ COMPLETION_ITEM_RESOLVE = 'completionItem/resolve',
588
+ DEFINITION = 'textDocument/definition',
589
+ DOCUMENT_HIGHLIGHT = 'textDocument/documentHighlight',
590
+ DOCUMENT_SYMBOL = 'textDocument/documentSymbol',
591
+ HOVER = 'textDocument/hover',
592
+ IMPLEMENTATION = 'textDocument/implementation',
593
+ INITIALIZE = 'initialize',
594
+ REFERENCES = 'textDocument/references',
595
+ RENAME = 'textDocument/rename',
596
+ SIGNATURE_HELP = 'textDocument/signatureHelp',
597
+ TYPE_DEFINITION = 'textDocument/typeDefinition',
598
+ FORMATTING = 'textDocument/formatting',
599
+ RANGE_FORMATTING = 'textDocument/rangeFormatting',
600
+ }
601
+ }
602
+
603
+ /**
604
+ * Interface describing the notifications that come from the server.
605
+ */
606
+ export interface IServerNotifyParams {
607
+ [Method.ServerNotification.LOG_MESSAGE]: lsp.LogMessageParams;
608
+ [Method.ServerNotification.LOG_TRACE]: rpc.LogTraceParams;
609
+ [Method.ServerNotification.PUBLISH_DIAGNOSTICS]: lsp.PublishDiagnosticsParams;
610
+ [Method.ServerNotification.SHOW_MESSAGE]: lsp.ShowMessageParams;
611
+ }
612
+
613
+ /**
614
+ * Interface describing the notifications that come from the client.
615
+ */
616
+ export interface IClientNotifyParams {
617
+ [Method.ClientNotification
618
+ .DID_CHANGE_CONFIGURATION]: lsp.DidChangeConfigurationParams;
619
+ [Method.ClientNotification.DID_CHANGE]: lsp.DidChangeTextDocumentParams;
620
+ [Method.ClientNotification.DID_OPEN]: lsp.DidOpenTextDocumentParams;
621
+ [Method.ClientNotification.DID_SAVE]: lsp.DidSaveTextDocumentParams;
622
+ [Method.ClientNotification.INITIALIZED]: lsp.InitializedParams;
623
+ [Method.ClientNotification.SET_TRACE]: rpc.SetTraceParams;
624
+ }
625
+
626
+ /**
627
+ * Interface describing the requests sent to the server.
628
+ */
629
+ export interface IServerRequestParams {
630
+ [Method.ServerRequest.REGISTER_CAPABILITY]: lsp.RegistrationParams;
631
+ [Method.ServerRequest.SHOW_MESSAGE_REQUEST]: lsp.ShowMessageRequestParams;
632
+ [Method.ServerRequest.UNREGISTER_CAPABILITY]: lsp.UnregistrationParams;
633
+ [Method.ServerRequest.WORKSPACE_CONFIGURATION]: lsp.ConfigurationParams;
634
+ }
635
+
636
+ /**
637
+ * Interface describing the responses received from the server.
638
+ */
639
+ export interface IServerResult {
640
+ [Method.ServerRequest.REGISTER_CAPABILITY]: void;
641
+ [Method.ServerRequest.SHOW_MESSAGE_REQUEST]: lsp.MessageActionItem | null;
642
+ [Method.ServerRequest.UNREGISTER_CAPABILITY]: void;
643
+ [Method.ServerRequest.WORKSPACE_CONFIGURATION]: any[];
644
+ }
645
+
646
+ /**
647
+ * Interface describing the request sent to the client.
648
+ */
649
+ export interface IClientRequestParams {
650
+ [Method.ClientRequest.COMPLETION_ITEM_RESOLVE]: lsp.CompletionItem;
651
+ [Method.ClientRequest.COMPLETION]: lsp.CompletionParams;
652
+ [Method.ClientRequest.DEFINITION]: lsp.TextDocumentPositionParams;
653
+ [Method.ClientRequest.DOCUMENT_HIGHLIGHT]: lsp.TextDocumentPositionParams;
654
+ [Method.ClientRequest.DOCUMENT_SYMBOL]: lsp.DocumentSymbolParams;
655
+ [Method.ClientRequest.HOVER]: lsp.TextDocumentPositionParams;
656
+ [Method.ClientRequest.IMPLEMENTATION]: lsp.TextDocumentPositionParams;
657
+ [Method.ClientRequest.INITIALIZE]: lsp.InitializeParams;
658
+ [Method.ClientRequest.REFERENCES]: lsp.ReferenceParams;
659
+ [Method.ClientRequest.RENAME]: lsp.RenameParams;
660
+ [Method.ClientRequest.SIGNATURE_HELP]: lsp.TextDocumentPositionParams;
661
+ [Method.ClientRequest.TYPE_DEFINITION]: lsp.TextDocumentPositionParams;
662
+ [Method.ClientRequest.FORMATTING]: lsp.DocumentFormattingParams;
663
+ [Method.ClientRequest.RANGE_FORMATTING]: lsp.DocumentRangeFormattingParams;
664
+ }
665
+
666
+ /**
667
+ * Interface describing the responses received from the client.
668
+ */
669
+ export interface IClientResult {
670
+ [Method.ClientRequest.COMPLETION_ITEM_RESOLVE]: lsp.CompletionItem;
671
+ [Method.ClientRequest.COMPLETION]: AnyCompletion;
672
+ [Method.ClientRequest.DEFINITION]: AnyLocation;
673
+ [Method.ClientRequest.DOCUMENT_HIGHLIGHT]: lsp.DocumentHighlight[];
674
+ [Method.ClientRequest.DOCUMENT_SYMBOL]: lsp.DocumentSymbol[];
675
+ [Method.ClientRequest.HOVER]: lsp.Hover | null;
676
+ [Method.ClientRequest.IMPLEMENTATION]: AnyLocation;
677
+ [Method.ClientRequest.INITIALIZE]: lsp.InitializeResult;
678
+ [Method.ClientRequest.REFERENCES]: lsp.Location[] | null;
679
+ [Method.ClientRequest.RENAME]: lsp.WorkspaceEdit;
680
+ [Method.ClientRequest.SIGNATURE_HELP]: lsp.SignatureHelp;
681
+ [Method.ClientRequest.TYPE_DEFINITION]: AnyLocation;
682
+ [Method.ClientRequest.FORMATTING]: lsp.TextEdit[] | null;
683
+ [Method.ClientRequest.RANGE_FORMATTING]: lsp.TextEdit[] | null;
684
+ }
685
+
686
+ /**
687
+ * Type of server notification handlers, it is a map between the server
688
+ * notification name and the associated `ISignal`.
689
+ */
690
+ export type ServerNotifications<
691
+ T extends keyof IServerNotifyParams = keyof IServerNotifyParams,
692
+ > = {
693
+ readonly [key in T]: Emitter<IServerNotifyParams[key]>;
694
+ };
695
+
696
+ /**
697
+ * Type of client notification handlers, it is a map between the client
698
+ * notification name and the associated signal.
699
+ */
700
+ export type ClientNotifications<
701
+ T extends keyof IClientNotifyParams = keyof IClientNotifyParams,
702
+ > = {
703
+ readonly [key in T]: Emitter<IClientNotifyParams[key]>;
704
+ };
705
+
706
+ /**
707
+ * Interface describing the client request handler.
708
+ */
709
+ export interface IClientRequestHandler<
710
+ T extends keyof IClientRequestParams = keyof IClientRequestParams,
711
+ > {
712
+ request(params: IClientRequestParams[T]): Promise<IClientResult[T]>;
713
+ }
714
+
715
+ /**
716
+ * Interface describing the server request handler.
717
+ */
718
+ export interface IServerRequestHandler<
719
+ T extends keyof IServerRequestParams = keyof IServerRequestParams,
720
+ > {
721
+ setHandler(
722
+ handler: (
723
+ params: IServerRequestParams[T],
724
+ connection?: ILSPConnection,
725
+ ) => Promise<IServerResult[T]>,
726
+ ): void;
727
+ clearHandler(): void;
728
+ }
729
+
730
+ /**
731
+ * Type of client request handlers, it is a map between the client
732
+ * request name and the associated handler.
733
+ */
734
+ export type ClientRequests<
735
+ T extends keyof IClientRequestParams = keyof IClientRequestParams,
736
+ > = {
737
+ // has async request(params) returning a promise with result.
738
+ readonly [key in T]: IClientRequestHandler<key>;
739
+ };
740
+
741
+ /**
742
+ * Type of server request handlers, it is a map between the server
743
+ * request name and the associated handler.
744
+ */
745
+ export type ServerRequests<
746
+ T extends keyof IServerRequestParams = keyof IServerRequestParams,
747
+ > = {
748
+ // has async request(params) returning a promise with result.
749
+ readonly [key in T]: IServerRequestHandler<key>;
750
+ };
751
+
752
+ /**
753
+ * @alpha
754
+ *
755
+ * Interface describing he connection to the language server.
756
+ */
757
+ export interface ILSPConnection extends ILspConnection {
758
+ /**
759
+ * @alpha
760
+ *
761
+ * Identifier of the language server
762
+ */
763
+ serverIdentifier?: string;
764
+
765
+ /**
766
+ * @alpha
767
+ *
768
+ * Language of the language server
769
+ */
770
+ serverLanguage?: string;
771
+
772
+ /**
773
+ * @alpha
774
+ *
775
+ * Should log all communication?
776
+ */
777
+ logAllCommunication: boolean;
778
+
779
+ /**
780
+ * @alpha
781
+ *
782
+ * Notifications that come from the client.
783
+ */
784
+ clientNotifications: ClientNotifications;
785
+
786
+ /**
787
+ * @alpha
788
+ *
789
+ * Notifications that come from the server.
790
+ */
791
+ serverNotifications: ServerNotifications;
792
+
793
+ /**
794
+ * @alpha
795
+ *
796
+ * Requests that come from the client.
797
+ */
798
+ clientRequests: ClientRequests;
799
+
800
+ /**
801
+ * @alpha
802
+ *
803
+ * Responses that come from the server.
804
+ */
805
+ serverRequests: ServerRequests;
806
+
807
+ /**
808
+ * @alpha
809
+ *
810
+ * Signal emitted when the connection is closed.
811
+ */
812
+ closeSignal: Event<boolean>;
813
+
814
+ /**
815
+ * @alpha
816
+ *
817
+ * Signal emitted when the connection receives an error
818
+ * message..
819
+ */
820
+ errorSignal: Event<any>;
821
+
822
+ /**
823
+ * @alpha
824
+ *
825
+ * Signal emitted when the connection is initialized.
826
+ */
827
+ serverInitialized: Event<lsp.ServerCapabilities<any>>;
828
+
829
+ /**
830
+ * @alpha
831
+ *
832
+ * Send the open request to the backend when the server is
833
+ * ready.
834
+ */
835
+ sendOpenWhenReady(documentInfo: IDocumentInfo): void;
836
+
837
+ /**
838
+ * @alpha
839
+ *
840
+ * Send all changes to the server.
841
+ */
842
+ sendFullTextChange(text: string, documentInfo: IDocumentInfo): void;
843
+ }