@jupyterlab/lsp 4.0.6 → 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 +4 -1
  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 +106 -9
  25. package/lib/tokens.js +8 -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 -11
  31. package/src/adapters/adapter.ts +34 -2
  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 +126 -12
  40. package/src/virtual/document.ts +26 -6
  41. package/style/index.css +2 -0
  42. package/style/index.js +2 -0
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
  */
@@ -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';