@jupyterlab/lsp 4.1.0-alpha.1 → 4.1.0-alpha.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 (42) hide show
  1. package/lib/adapters/adapter.d.ts +6 -3
  2. package/lib/adapters/adapter.js +21 -0
  3. package/lib/adapters/adapter.js.map +1 -1
  4. package/lib/adapters/editorAdapter.d.ts +74 -0
  5. package/lib/adapters/editorAdapter.js +53 -0
  6. package/lib/adapters/editorAdapter.js.map +1 -0
  7. package/lib/adapters/index.d.ts +3 -0
  8. package/lib/adapters/index.js +6 -0
  9. package/lib/adapters/index.js.map +1 -0
  10. package/lib/adapters/tracker.d.ts +106 -0
  11. package/lib/adapters/tracker.js +175 -0
  12. package/lib/adapters/tracker.js.map +1 -0
  13. package/lib/connection_manager.d.ts +11 -5
  14. package/lib/connection_manager.js +10 -0
  15. package/lib/connection_manager.js.map +1 -1
  16. package/lib/feature.d.ts +7 -2
  17. package/lib/feature.js +17 -4
  18. package/lib/feature.js.map +1 -1
  19. package/lib/index.d.ts +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/index.js.map +1 -1
  22. package/lib/lsp.d.ts +1 -0
  23. package/lib/lsp.js.map +1 -1
  24. package/lib/tokens.d.ts +132 -10
  25. package/lib/tokens.js +17 -0
  26. package/lib/tokens.js.map +1 -1
  27. package/lib/virtual/document.d.ts +1 -2
  28. package/lib/virtual/document.js +22 -5
  29. package/lib/virtual/document.js.map +1 -1
  30. package/package.json +10 -8
  31. package/src/adapters/adapter.ts +36 -4
  32. package/src/adapters/editorAdapter.ts +131 -0
  33. package/src/adapters/index.ts +6 -0
  34. package/src/adapters/tracker.ts +222 -0
  35. package/src/connection_manager.ts +23 -7
  36. package/src/feature.ts +20 -5
  37. package/src/index.ts +1 -1
  38. package/src/lsp.ts +2 -0
  39. package/src/tokens.ts +155 -13
  40. package/src/virtual/document.ts +26 -6
  41. package/style/index.css +2 -0
  42. package/style/index.js +2 -0
package/src/feature.ts CHANGED
@@ -6,13 +6,14 @@ import mergeWith from 'lodash.mergewith';
6
6
 
7
7
  import { ClientCapabilities } from './lsp';
8
8
  import { IFeature, ILSPFeatureManager } from './tokens';
9
+ import { EditorAdapter } from './adapters/editorAdapter';
9
10
 
10
11
  /**
11
12
  * Class to manager the registered features of the language servers.
12
13
  */
13
14
  export class FeatureManager implements ILSPFeatureManager {
14
15
  constructor() {
15
- this._featuresRegistered = new Signal(this);
16
+ this._featureRegistered = new Signal(this);
16
17
  }
17
18
  /**
18
19
  * List of registered features
@@ -22,8 +23,8 @@ export class FeatureManager implements ILSPFeatureManager {
22
23
  /**
23
24
  * Signal emitted when a new feature is registered.
24
25
  */
25
- get featuresRegistered(): ISignal<ILSPFeatureManager, IFeature> {
26
- return this._featuresRegistered;
26
+ get featureRegistered(): ISignal<ILSPFeatureManager, IFeature> {
27
+ return this._featureRegistered;
27
28
  }
28
29
 
29
30
  /**
@@ -36,7 +37,7 @@ export class FeatureManager implements ILSPFeatureManager {
36
37
  );
37
38
  } else {
38
39
  this.features.push(feature);
39
- this._featuresRegistered.emit(feature);
40
+ this._featureRegistered.emit(feature);
40
41
  }
41
42
  }
42
43
 
@@ -54,5 +55,19 @@ export class FeatureManager implements ILSPFeatureManager {
54
55
  return capabilities;
55
56
  }
56
57
 
57
- private _featuresRegistered: Signal<ILSPFeatureManager, IFeature>;
58
+ /**
59
+ * Get the extension factories of all clients.
60
+ */
61
+ extensionFactories(): EditorAdapter.ILSPEditorExtensionFactory[] {
62
+ const factories: EditorAdapter.ILSPEditorExtensionFactory[] = [];
63
+ for (const feature of this.features) {
64
+ if (!feature.extensionFactory) {
65
+ continue;
66
+ }
67
+ factories.push(feature.extensionFactory);
68
+ }
69
+ return factories;
70
+ }
71
+
72
+ private _featureRegistered: Signal<ILSPFeatureManager, IFeature>;
58
73
  }
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @module lsp
6
6
  */
7
7
 
8
- export * from './adapters/adapter';
8
+ export * from './adapters';
9
9
  export * from './connection_manager';
10
10
  export * from './extractors';
11
11
  export * from './feature';
package/src/lsp.ts CHANGED
@@ -5,6 +5,8 @@ import type * as lsp from 'vscode-languageserver-protocol';
5
5
 
6
6
  export type ClientCapabilities = lsp.ClientCapabilities;
7
7
 
8
+ export type ServerCapabilities = lsp.ServerCapabilities;
9
+
8
10
  export enum DiagnosticSeverity {
9
11
  Error = 1,
10
12
  Warning = 2,
package/src/tokens.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
- import { IDocumentWidget } from '@jupyterlab/docregistry';
5
4
  import { ServerConnection } from '@jupyterlab/services';
5
+ import { CodeEditor } from '@jupyterlab/codeeditor';
6
+
7
+ import { FocusTracker, Widget } from '@lumino/widgets';
6
8
  import { Token } from '@lumino/coreutils';
7
9
  import { IDisposable, IObservableDisposable } from '@lumino/disposable';
8
10
  import { ISignal, Signal } from '@lumino/signaling';
9
11
 
10
- import { WidgetLSPAdapter } from './adapters/adapter';
12
+ import { EditorAdapter, WidgetLSPAdapter } from './adapters';
11
13
  import { IForeignCodeExtractor } from './extractors/types';
12
14
  import {
13
15
  AnyCompletion,
@@ -26,7 +28,7 @@ import {
26
28
 
27
29
  import type * as rpc from 'vscode-jsonrpc';
28
30
  import type * as lsp from 'vscode-languageserver-protocol';
29
- import { CodeEditor } from '@jupyterlab/codeeditor';
31
+
30
32
  export { IDocumentInfo };
31
33
 
32
34
  /**
@@ -367,9 +369,10 @@ export interface ILSPDocumentConnectionManager {
367
369
  documents: Map<VirtualDocument.uri, VirtualDocument>;
368
370
 
369
371
  /**
372
+ * @deprecated
370
373
  * The mapping of document uri to the widget adapter.
371
374
  */
372
- adapters: Map<string, WidgetLSPAdapter<IDocumentWidget>>;
375
+ adapters: Map<string, WidgetLSPAdapter>;
373
376
 
374
377
  /**
375
378
  * Signal emitted when a connection is connected.
@@ -472,15 +475,14 @@ export interface ILSPDocumentConnectionManager {
472
475
  unregisterDocument(uri: string): void;
473
476
 
474
477
  /**
478
+ * @deprecated
479
+ *
475
480
  * Register a widget adapter.
476
481
  *
477
482
  * @param path - path to current document widget of input adapter
478
483
  * @param adapter - the adapter need to be registered
479
484
  */
480
- registerAdapter(
481
- path: string,
482
- adapter: WidgetLSPAdapter<IDocumentWidget>
483
- ): void;
485
+ registerAdapter(path: string, adapter: WidgetLSPAdapter): void;
484
486
  }
485
487
 
486
488
  /**
@@ -498,6 +500,11 @@ export interface IFeature {
498
500
  * LSP capabilities implemented by the feature.
499
501
  */
500
502
  capabilities?: ClientCapabilities;
503
+
504
+ /**
505
+ * Editor extension factory linked to the LSP feature.
506
+ */
507
+ extensionFactory?: EditorAdapter.ILSPEditorExtensionFactory;
501
508
  }
502
509
 
503
510
  /**
@@ -511,6 +518,11 @@ export interface ILSPFeatureManager {
511
518
  */
512
519
  readonly features: IFeature[];
513
520
 
521
+ /**
522
+ * Signal emitted when a feature is registered
523
+ */
524
+ featureRegistered: ISignal<ILSPFeatureManager, IFeature>;
525
+
514
526
  /**
515
527
  * Register the new feature (frontend capability)
516
528
  * for one or more code editor implementations.
@@ -518,14 +530,14 @@ export interface ILSPFeatureManager {
518
530
  register(feature: IFeature): void;
519
531
 
520
532
  /**
521
- * Signal emitted when a feature is registered
533
+ * Get capabilities of all registered features
522
534
  */
523
- featuresRegistered: ISignal<ILSPFeatureManager, IFeature>;
535
+ clientCapabilities(): ClientCapabilities;
524
536
 
525
537
  /**
526
- * Get capabilities of all registered features
538
+ * Get the extension factories of all clients.
527
539
  */
528
- clientCapabilities(): ClientCapabilities;
540
+ extensionFactories(): EditorAdapter.ILSPEditorExtensionFactory[];
529
541
  }
530
542
 
531
543
  /**
@@ -551,6 +563,96 @@ export interface ILSPCodeExtractorsManager {
551
563
  ): void;
552
564
  }
553
565
 
566
+ /**
567
+ * An interface with the necessary properties from `JupyterFrontEnd.IShell`
568
+ * for the `WidgetLSPAdapterTracker`. Used to track the active DocumentWidget.
569
+ *
570
+ * For more info see https://github.com/jupyterlab/jupyterlab/pull/14920#discussion_r1316507818
571
+ * and https://github.com/jupyterlab/jupyterlab/pull/14920#discussion_r1305019718 .
572
+ */
573
+ export interface IShell {
574
+ /**
575
+ * The active widget in the shell's main area.
576
+ */
577
+ readonly activeWidget: Widget | null;
578
+ /**
579
+ * A signal emitted when main area's current focus changes.
580
+ */
581
+ readonly currentChanged: ISignal<this, FocusTracker.IChangedArgs<Widget>>;
582
+ }
583
+
584
+ /**
585
+ * A tracker that tracks WidgetLSPAdapters.
586
+ *
587
+ * @typeparam T - The type of widget being tracked. Defaults to `WidgetLSPAdapter`.
588
+ */
589
+ export interface IWidgetLSPAdapterTracker<
590
+ T extends WidgetLSPAdapter = WidgetLSPAdapter
591
+ > extends IDisposable {
592
+ /**
593
+ * A signal emitted when an adapter is added.
594
+ */
595
+ readonly adapterAdded: ISignal<this, T>;
596
+
597
+ /**
598
+ * The current adapter is the most recently focused or added adapter.
599
+ *
600
+ * #### Notes
601
+ * It is the most recently focused adapter, or the most recently added
602
+ * adapter if no adapter has taken focus.
603
+ */
604
+ readonly currentAdapter: T | null;
605
+
606
+ /**
607
+ * A signal emitted when the current instance changes.
608
+ *
609
+ * #### Notes
610
+ * If the last instance being tracked is disposed, `null` will be emitted.
611
+ */
612
+ readonly currentChanged: ISignal<this, T | null>;
613
+
614
+ /**
615
+ * The number of instances held by the tracker.
616
+ */
617
+ readonly size: number;
618
+
619
+ /**
620
+ * A signal emitted when a adapter is updated.
621
+ */
622
+ readonly adapterUpdated: ISignal<this, T>;
623
+
624
+ /**
625
+ * Find the first instance in the tracker that satisfies a filter function.
626
+ *
627
+ * @param - fn The filter function to call on each instance.
628
+ *
629
+ * #### Notes
630
+ * If nothing is found, the value returned is `undefined`.
631
+ */
632
+ find(fn: (obj: T) => boolean): T | undefined;
633
+
634
+ /**
635
+ * Iterate through each instance in the tracker.
636
+ *
637
+ * @param fn - The function to call on each instance.
638
+ */
639
+ forEach(fn: (obj: T) => void): void;
640
+
641
+ /**
642
+ * Filter the instances in the tracker based on a predicate.
643
+ *
644
+ * @param fn - The function by which to filter.
645
+ */
646
+ filter(fn: (obj: T) => boolean): T[];
647
+
648
+ /**
649
+ * Check if this tracker has the specified instance.
650
+ *
651
+ * @param obj - The object whose existence is being checked.
652
+ */
653
+ has(obj: T): boolean;
654
+ }
655
+
554
656
  /**
555
657
  * @alpha
556
658
  *
@@ -590,6 +692,18 @@ export const ILSPCodeExtractorsManager = new Token<ILSPCodeExtractorsManager>(
590
692
  'Provides the code extractor manager. This token is required in your extension to register code extractor allowing the creation of multiple virtual document from an opened document.'
591
693
  );
592
694
 
695
+ /**
696
+ * @alpha
697
+ *
698
+ * The WidgetLSPAdapter tracker. Require this token in your extension to
699
+ * track WidgetLSPAdapters.
700
+ *
701
+ */
702
+ export const IWidgetLSPAdapterTracker = new Token<IWidgetLSPAdapterTracker>(
703
+ '@jupyterlab/lsp:IWidgetLSPAdapterTracker',
704
+ 'Provides the WidgetLSPAdapter tracker. This token is required in your extension to track WidgetLSPAdapters.'
705
+ );
706
+
593
707
  /**
594
708
  * Argument for creating a connection to the LSP proxy server.
595
709
  */
@@ -638,9 +752,11 @@ export namespace Method {
638
752
 
639
753
  /** Client requests */
640
754
  export enum ClientRequest {
755
+ CODE_ACTION = 'textDocument/codeAction',
641
756
  COMPLETION = 'textDocument/completion',
642
757
  COMPLETION_ITEM_RESOLVE = 'completionItem/resolve',
643
758
  DEFINITION = 'textDocument/definition',
759
+ DOCUMENT_COLOR = 'textDocument/documentColor',
644
760
  DOCUMENT_HIGHLIGHT = 'textDocument/documentHighlight',
645
761
  DOCUMENT_SYMBOL = 'textDocument/documentSymbol',
646
762
  HOVER = 'textDocument/hover',
@@ -649,7 +765,14 @@ export namespace Method {
649
765
  REFERENCES = 'textDocument/references',
650
766
  RENAME = 'textDocument/rename',
651
767
  SIGNATURE_HELP = 'textDocument/signatureHelp',
652
- TYPE_DEFINITION = 'textDocument/typeDefinition'
768
+ TYPE_DEFINITION = 'textDocument/typeDefinition',
769
+ LINKED_EDITING_RANGE = 'textDocument/linkedEditingRange',
770
+ INLINE_VALUE = 'textDocument/inlineValue',
771
+ INLAY_HINT = 'textDocument/inlayHint',
772
+ WORKSPACE_SYMBOL = 'workspace/symbol',
773
+ WORKSPACE_SYMBOL_RESOLVE = 'workspaceSymbol/resolve',
774
+ FORMATTING = 'textDocument/formatting',
775
+ RANGE_FORMATTING = 'textDocument/rangeFormatting'
653
776
  }
654
777
  }
655
778
 
@@ -700,9 +823,11 @@ export interface IServerResult {
700
823
  * Interface describing the request sent to the client.
701
824
  */
702
825
  export interface IClientRequestParams {
826
+ [Method.ClientRequest.CODE_ACTION]: lsp.CodeActionParams;
703
827
  [Method.ClientRequest.COMPLETION_ITEM_RESOLVE]: lsp.CompletionItem;
704
828
  [Method.ClientRequest.COMPLETION]: lsp.CompletionParams;
705
829
  [Method.ClientRequest.DEFINITION]: lsp.TextDocumentPositionParams;
830
+ [Method.ClientRequest.DOCUMENT_COLOR]: lsp.DocumentColorParams;
706
831
  [Method.ClientRequest.DOCUMENT_HIGHLIGHT]: lsp.TextDocumentPositionParams;
707
832
  [Method.ClientRequest.DOCUMENT_SYMBOL]: lsp.DocumentSymbolParams;
708
833
  [Method.ClientRequest.HOVER]: lsp.TextDocumentPositionParams;
@@ -712,15 +837,23 @@ export interface IClientRequestParams {
712
837
  [Method.ClientRequest.RENAME]: lsp.RenameParams;
713
838
  [Method.ClientRequest.SIGNATURE_HELP]: lsp.TextDocumentPositionParams;
714
839
  [Method.ClientRequest.TYPE_DEFINITION]: lsp.TextDocumentPositionParams;
840
+ [Method.ClientRequest.INLINE_VALUE]: lsp.InlineValueParams;
841
+ [Method.ClientRequest.INLAY_HINT]: lsp.InlayHintParams;
842
+ [Method.ClientRequest.WORKSPACE_SYMBOL]: lsp.WorkspaceSymbolParams;
843
+ [Method.ClientRequest.WORKSPACE_SYMBOL_RESOLVE]: lsp.WorkspaceSymbol;
844
+ [Method.ClientRequest.FORMATTING]: lsp.DocumentFormattingParams;
845
+ [Method.ClientRequest.RANGE_FORMATTING]: lsp.DocumentRangeFormattingParams;
715
846
  }
716
847
 
717
848
  /**
718
849
  * Interface describing the responses received from the client.
719
850
  */
720
851
  export interface IClientResult {
852
+ [Method.ClientRequest.CODE_ACTION]: (lsp.Command | lsp.CodeAction)[] | null;
721
853
  [Method.ClientRequest.COMPLETION_ITEM_RESOLVE]: lsp.CompletionItem;
722
854
  [Method.ClientRequest.COMPLETION]: AnyCompletion;
723
855
  [Method.ClientRequest.DEFINITION]: AnyLocation;
856
+ [Method.ClientRequest.DOCUMENT_COLOR]: lsp.ColorInformation[];
724
857
  [Method.ClientRequest.DOCUMENT_HIGHLIGHT]: lsp.DocumentHighlight[];
725
858
  [Method.ClientRequest.DOCUMENT_SYMBOL]: lsp.DocumentSymbol[];
726
859
  [Method.ClientRequest.HOVER]: lsp.Hover | null;
@@ -730,6 +863,15 @@ export interface IClientResult {
730
863
  [Method.ClientRequest.RENAME]: lsp.WorkspaceEdit;
731
864
  [Method.ClientRequest.SIGNATURE_HELP]: lsp.SignatureHelp;
732
865
  [Method.ClientRequest.TYPE_DEFINITION]: AnyLocation;
866
+ [Method.ClientRequest.INLINE_VALUE]: lsp.InlineValue[] | null;
867
+ [Method.ClientRequest.INLAY_HINT]: lsp.InlayHint[] | null;
868
+ [Method.ClientRequest.WORKSPACE_SYMBOL]:
869
+ | lsp.SymbolInformation[]
870
+ | lsp.WorkspaceSymbol[]
871
+ | null;
872
+ [Method.ClientRequest.WORKSPACE_SYMBOL_RESOLVE]: lsp.WorkspaceSymbol[];
873
+ [Method.ClientRequest.FORMATTING]: lsp.TextEdit[] | null;
874
+ [Method.ClientRequest.RANGE_FORMATTING]: lsp.TextEdit[] | null;
733
875
  }
734
876
 
735
877
  /**
@@ -241,7 +241,6 @@ export class VirtualDocument implements IDisposable {
241
241
  );
242
242
  this._remainingLifetime = 6;
243
243
 
244
- this.unusedDocuments = new Set();
245
244
  this.documentInfo = new VirtualDocumentInfo(this);
246
245
  this.updateManager = new UpdateManager(this);
247
246
  this.updateManager.updateBegan.connect(this._updateBeganSlot, this);
@@ -446,7 +445,6 @@ export class VirtualDocument implements IDisposable {
446
445
 
447
446
  this.foreignDocuments.clear();
448
447
  this.sourceLines.clear();
449
- this.unusedDocuments.clear();
450
448
  this.unusedStandaloneDocuments.clear();
451
449
  this.virtualLines.clear();
452
450
 
@@ -470,7 +468,6 @@ export class VirtualDocument implements IDisposable {
470
468
  // TODO - deep clear (assure that there is no memory leak)
471
469
  this.unusedStandaloneDocuments.clear();
472
470
 
473
- this.unusedDocuments = new Set();
474
471
  this.virtualLines.clear();
475
472
  this.sourceLines.clear();
476
473
  this.lastVirtualLine = 0;
@@ -806,10 +803,34 @@ export class VirtualDocument implements IDisposable {
806
803
  * Close all expired documents.
807
804
  */
808
805
  closeExpiredDocuments(): void {
809
- for (let document of this.unusedDocuments.values()) {
806
+ const usedDocuments = new Set<VirtualDocument>();
807
+ for (const line of this.sourceLines.values()) {
808
+ for (const block of line.foreignDocumentsMap.values()) {
809
+ usedDocuments.add(block.virtualDocument);
810
+ }
811
+ }
812
+
813
+ const documentIDs = new Map<VirtualDocument, string[]>();
814
+ for (const [id, document] of this.foreignDocuments.entries()) {
815
+ const ids = documentIDs.get(document);
816
+ if (typeof ids !== 'undefined') {
817
+ documentIDs.set(document, [...ids, id]);
818
+ }
819
+ documentIDs.set(document, [id]);
820
+ }
821
+ const allDocuments = new Set<VirtualDocument>(documentIDs.keys());
822
+ const unusedVirtualDocuments = new Set(
823
+ [...allDocuments].filter(x => !usedDocuments.has(x))
824
+ );
825
+
826
+ for (let document of unusedVirtualDocuments.values()) {
810
827
  document.remainingLifetime -= 1;
811
828
  if (document.remainingLifetime <= 0) {
812
829
  document.dispose();
830
+ const ids = documentIDs.get(document)!;
831
+ for (const id of ids) {
832
+ this.foreignDocuments.delete(id);
833
+ }
813
834
  }
814
835
  }
815
836
  }
@@ -901,7 +922,7 @@ export class VirtualDocument implements IDisposable {
901
922
 
902
923
  /**
903
924
  * When this counter goes down to 0, the document will be destroyed and the associated connection will be closed;
904
- * This is meant to reduce the number of open connections when a a foreign code snippet was removed from the document.
925
+ * This is meant to reduce the number of open connections when a foreign code snippet was removed from the document.
905
926
  *
906
927
  * Note: top level virtual documents are currently immortal (unless killed by other means); it might be worth
907
928
  * implementing culling of unused documents, but if and only if JupyterLab will also implement culling of
@@ -927,7 +948,6 @@ export class VirtualDocument implements IDisposable {
927
948
  protected sourceLines: Map<number, ISourceLine>;
928
949
  protected lineBlocks: Array<string>;
929
950
 
930
- protected unusedDocuments: Set<VirtualDocument>;
931
951
  protected unusedStandaloneDocuments: DefaultMap<
932
952
  language,
933
953
  Array<VirtualDocument>
package/style/index.css CHANGED
@@ -4,6 +4,8 @@
4
4
  |----------------------------------------------------------------------------*/
5
5
 
6
6
  /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+ @import url('~@lumino/widgets/style/index.css');
7
8
  @import url('~@jupyterlab/apputils/style/index.css');
8
9
  @import url('~@jupyterlab/codeeditor/style/index.css');
10
+ @import url('~@jupyterlab/codemirror/style/index.css');
9
11
  @import url('~@jupyterlab/docregistry/style/index.css');
package/style/index.js CHANGED
@@ -4,6 +4,8 @@
4
4
  |----------------------------------------------------------------------------*/
5
5
 
6
6
  /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+ import '@lumino/widgets/style/index.js';
7
8
  import '@jupyterlab/apputils/style/index.js';
8
9
  import '@jupyterlab/codeeditor/style/index.js';
10
+ import '@jupyterlab/codemirror/style/index.js';
9
11
  import '@jupyterlab/docregistry/style/index.js';