@jupyterlab/lsp 4.1.0-alpha.1 → 4.1.0-alpha.3
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.
- package/lib/adapters/adapter.d.ts +20 -3
- package/lib/adapters/adapter.js +55 -2
- package/lib/adapters/adapter.js.map +1 -1
- package/lib/adapters/editorAdapter.d.ts +74 -0
- package/lib/adapters/editorAdapter.js +53 -0
- package/lib/adapters/editorAdapter.js.map +1 -0
- package/lib/adapters/index.d.ts +3 -0
- package/lib/adapters/index.js +6 -0
- package/lib/adapters/index.js.map +1 -0
- package/lib/adapters/tracker.d.ts +106 -0
- package/lib/adapters/tracker.js +175 -0
- package/lib/adapters/tracker.js.map +1 -0
- package/lib/connection_manager.d.ts +11 -5
- package/lib/connection_manager.js +10 -0
- package/lib/connection_manager.js.map +1 -1
- package/lib/feature.d.ts +7 -2
- package/lib/feature.js +17 -4
- package/lib/feature.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/lsp.d.ts +1 -0
- package/lib/lsp.js.map +1 -1
- package/lib/tokens.d.ts +132 -10
- package/lib/tokens.js +17 -0
- package/lib/tokens.js.map +1 -1
- package/lib/virtual/document.d.ts +7 -3
- package/lib/virtual/document.js +51 -13
- package/lib/virtual/document.js.map +1 -1
- package/package.json +12 -10
- package/src/adapters/adapter.ts +87 -6
- package/src/adapters/editorAdapter.ts +131 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/tracker.ts +222 -0
- package/src/connection_manager.ts +23 -7
- package/src/feature.ts +20 -5
- package/src/index.ts +1 -1
- package/src/lsp.ts +2 -0
- package/src/tokens.ts +155 -13
- package/src/virtual/document.ts +62 -16
- package/style/index.css +2 -0
- package/style/index.js +2 -0
package/src/virtual/document.ts
CHANGED
|
@@ -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
|
|
|
@@ -463,14 +461,16 @@ export class VirtualDocument implements IDisposable {
|
|
|
463
461
|
* Clear the virtual document and all related stuffs
|
|
464
462
|
*/
|
|
465
463
|
clear(): void {
|
|
464
|
+
this.unusedStandaloneDocuments.clear();
|
|
465
|
+
|
|
466
466
|
for (let document of this.foreignDocuments.values()) {
|
|
467
467
|
document.clear();
|
|
468
|
+
if (document.standalone) {
|
|
469
|
+
let set = this.unusedStandaloneDocuments.get(document.language);
|
|
470
|
+
set.push(document);
|
|
471
|
+
}
|
|
468
472
|
}
|
|
469
473
|
|
|
470
|
-
// TODO - deep clear (assure that there is no memory leak)
|
|
471
|
-
this.unusedStandaloneDocuments.clear();
|
|
472
|
-
|
|
473
|
-
this.unusedDocuments = new Set();
|
|
474
474
|
this.virtualLines.clear();
|
|
475
475
|
this.sourceLines.clear();
|
|
476
476
|
this.lastVirtualLine = 0;
|
|
@@ -742,7 +742,7 @@ export class VirtualDocument implements IDisposable {
|
|
|
742
742
|
);
|
|
743
743
|
continue;
|
|
744
744
|
}
|
|
745
|
-
let foreignDocument = this.
|
|
745
|
+
let foreignDocument = this._chooseForeignDocument(extractor);
|
|
746
746
|
foreignDocumentsMap.set(result.range, {
|
|
747
747
|
virtualLine: foreignDocument.lastVirtualLine,
|
|
748
748
|
virtualDocument: foreignDocument,
|
|
@@ -806,10 +806,34 @@ export class VirtualDocument implements IDisposable {
|
|
|
806
806
|
* Close all expired documents.
|
|
807
807
|
*/
|
|
808
808
|
closeExpiredDocuments(): void {
|
|
809
|
-
|
|
809
|
+
const usedDocuments = new Set<VirtualDocument>();
|
|
810
|
+
for (const line of this.sourceLines.values()) {
|
|
811
|
+
for (const block of line.foreignDocumentsMap.values()) {
|
|
812
|
+
usedDocuments.add(block.virtualDocument);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const documentIDs = new Map<VirtualDocument, string[]>();
|
|
817
|
+
for (const [id, document] of this.foreignDocuments.entries()) {
|
|
818
|
+
const ids = documentIDs.get(document);
|
|
819
|
+
if (typeof ids !== 'undefined') {
|
|
820
|
+
documentIDs.set(document, [...ids, id]);
|
|
821
|
+
}
|
|
822
|
+
documentIDs.set(document, [id]);
|
|
823
|
+
}
|
|
824
|
+
const allDocuments = new Set<VirtualDocument>(documentIDs.keys());
|
|
825
|
+
const unusedVirtualDocuments = new Set(
|
|
826
|
+
[...allDocuments].filter(x => !usedDocuments.has(x))
|
|
827
|
+
);
|
|
828
|
+
|
|
829
|
+
for (let document of unusedVirtualDocuments.values()) {
|
|
810
830
|
document.remainingLifetime -= 1;
|
|
811
831
|
if (document.remainingLifetime <= 0) {
|
|
812
832
|
document.dispose();
|
|
833
|
+
const ids = documentIDs.get(document)!;
|
|
834
|
+
for (const id of ids) {
|
|
835
|
+
this.foreignDocuments.delete(id);
|
|
836
|
+
}
|
|
813
837
|
}
|
|
814
838
|
}
|
|
815
839
|
}
|
|
@@ -867,6 +891,19 @@ export class VirtualDocument implements IDisposable {
|
|
|
867
891
|
} as ISourcePosition;
|
|
868
892
|
}
|
|
869
893
|
|
|
894
|
+
/**
|
|
895
|
+
* Compute the position in root document from the position of
|
|
896
|
+
* a virtual document.
|
|
897
|
+
*/
|
|
898
|
+
transformVirtualToRoot(position: IVirtualPosition): IRootPosition | null {
|
|
899
|
+
const editor = this.virtualLines.get(position.line)?.editor;
|
|
900
|
+
const editorPosition = this.transformVirtualToEditor(position);
|
|
901
|
+
if (!editor || !editorPosition) {
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
return this.root.transformFromEditorToRoot(editor, editorPosition);
|
|
905
|
+
}
|
|
906
|
+
|
|
870
907
|
/**
|
|
871
908
|
* Get the corresponding editor of the virtual line.
|
|
872
909
|
*/
|
|
@@ -901,7 +938,7 @@ export class VirtualDocument implements IDisposable {
|
|
|
901
938
|
|
|
902
939
|
/**
|
|
903
940
|
* 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
|
|
941
|
+
* This is meant to reduce the number of open connections when a foreign code snippet was removed from the document.
|
|
905
942
|
*
|
|
906
943
|
* Note: top level virtual documents are currently immortal (unless killed by other means); it might be worth
|
|
907
944
|
* implementing culling of unused documents, but if and only if JupyterLab will also implement culling of
|
|
@@ -927,7 +964,6 @@ export class VirtualDocument implements IDisposable {
|
|
|
927
964
|
protected sourceLines: Map<number, ISourceLine>;
|
|
928
965
|
protected lineBlocks: Array<string>;
|
|
929
966
|
|
|
930
|
-
protected unusedDocuments: Set<VirtualDocument>;
|
|
931
967
|
protected unusedStandaloneDocuments: DefaultMap<
|
|
932
968
|
language,
|
|
933
969
|
Array<VirtualDocument>
|
|
@@ -945,7 +981,7 @@ export class VirtualDocument implements IDisposable {
|
|
|
945
981
|
/**
|
|
946
982
|
* Get the foreign document that can be opened with the input extractor.
|
|
947
983
|
*/
|
|
948
|
-
private
|
|
984
|
+
private _chooseForeignDocument(
|
|
949
985
|
extractor: IForeignCodeExtractor
|
|
950
986
|
): VirtualDocument {
|
|
951
987
|
let foreignDocument: VirtualDocument;
|
|
@@ -956,11 +992,18 @@ export class VirtualDocument implements IDisposable {
|
|
|
956
992
|
} else {
|
|
957
993
|
// if (previous document does not exists) or (extractor produces standalone documents
|
|
958
994
|
// and no old standalone document could be reused): create a new document
|
|
959
|
-
|
|
960
|
-
extractor.language
|
|
961
|
-
extractor.standalone,
|
|
962
|
-
extractor.fileExtension
|
|
995
|
+
let unusedStandalone = this.unusedStandaloneDocuments.get(
|
|
996
|
+
extractor.language
|
|
963
997
|
);
|
|
998
|
+
if (extractor.standalone && unusedStandalone.length > 0) {
|
|
999
|
+
foreignDocument = unusedStandalone.pop()!;
|
|
1000
|
+
} else {
|
|
1001
|
+
foreignDocument = this.openForeign(
|
|
1002
|
+
extractor.language,
|
|
1003
|
+
extractor.standalone,
|
|
1004
|
+
extractor.fileExtension
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
964
1007
|
}
|
|
965
1008
|
return foreignDocument;
|
|
966
1009
|
}
|
|
@@ -977,13 +1020,16 @@ export class VirtualDocument implements IDisposable {
|
|
|
977
1020
|
standalone: boolean,
|
|
978
1021
|
fileExtension: string
|
|
979
1022
|
): VirtualDocument {
|
|
980
|
-
let document = new
|
|
1023
|
+
let document = new (this.constructor as new (
|
|
1024
|
+
...args: ConstructorParameters<typeof VirtualDocument>
|
|
1025
|
+
) => VirtualDocument)({
|
|
981
1026
|
...this.options,
|
|
982
1027
|
parent: this,
|
|
983
1028
|
standalone: standalone,
|
|
984
1029
|
fileExtension: fileExtension,
|
|
985
1030
|
language: language
|
|
986
1031
|
});
|
|
1032
|
+
|
|
987
1033
|
const context: Document.IForeignContext = {
|
|
988
1034
|
foreignDocument: document,
|
|
989
1035
|
parentHost: this
|
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';
|