@jupyterlab/lsp 4.0.0-alpha.11

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 (51) hide show
  1. package/lib/adapters/adapter.d.ts +125 -0
  2. package/lib/adapters/adapter.js +382 -0
  3. package/lib/adapters/adapter.js.map +1 -0
  4. package/lib/connection.d.ts +65 -0
  5. package/lib/connection.js +309 -0
  6. package/lib/connection.js.map +1 -0
  7. package/lib/connection_manager.d.ts +71 -0
  8. package/lib/connection_manager.js +312 -0
  9. package/lib/connection_manager.js.map +1 -0
  10. package/lib/extractors/manager.d.ts +13 -0
  11. package/lib/extractors/manager.js +44 -0
  12. package/lib/extractors/manager.js.map +1 -0
  13. package/lib/extractors/text_extractor.d.ts +28 -0
  14. package/lib/extractors/text_extractor.js +27 -0
  15. package/lib/extractors/text_extractor.js.map +1 -0
  16. package/lib/extractors/types.d.ts +65 -0
  17. package/lib/extractors/types.js +2 -0
  18. package/lib/extractors/types.js.map +1 -0
  19. package/lib/feature.d.ts +11 -0
  20. package/lib/feature.js +31 -0
  21. package/lib/feature.js.map +1 -0
  22. package/lib/index.d.ts +17 -0
  23. package/lib/index.js +22 -0
  24. package/lib/index.js.map +1 -0
  25. package/lib/lsp.d.ts +129 -0
  26. package/lib/lsp.js +125 -0
  27. package/lib/lsp.js.map +1 -0
  28. package/lib/manager.d.ts +29 -0
  29. package/lib/manager.js +130 -0
  30. package/lib/manager.js.map +1 -0
  31. package/lib/plugin.d.ts +45 -0
  32. package/lib/plugin.js +3 -0
  33. package/lib/plugin.js.map +1 -0
  34. package/lib/positioning.d.ts +28 -0
  35. package/lib/positioning.js +49 -0
  36. package/lib/positioning.js.map +1 -0
  37. package/lib/schema.d.ts +228 -0
  38. package/lib/schema.js +3 -0
  39. package/lib/schema.js.map +1 -0
  40. package/lib/tokens.d.ts +368 -0
  41. package/lib/tokens.js +58 -0
  42. package/lib/tokens.js.map +1 -0
  43. package/lib/utils.d.ts +18 -0
  44. package/lib/utils.js +71 -0
  45. package/lib/utils.js.map +1 -0
  46. package/lib/virtual/document.d.ts +270 -0
  47. package/lib/virtual/document.js +600 -0
  48. package/lib/virtual/document.js.map +1 -0
  49. package/package.json +75 -0
  50. package/style/index.css +11 -0
  51. package/style/index.js +11 -0
package/lib/utils.js ADDED
@@ -0,0 +1,71 @@
1
+ import mergeWith from 'lodash.mergewith';
2
+ export async function sleep(timeout) {
3
+ return new Promise(resolve => {
4
+ setTimeout(() => {
5
+ resolve();
6
+ }, timeout);
7
+ });
8
+ }
9
+ export function untilReady(isReady, maxRetrials = 35, interval = 50, intervalModifier = (i) => i) {
10
+ return (async () => {
11
+ let i = 0;
12
+ while (isReady() !== true) {
13
+ i += 1;
14
+ if (maxRetrials !== -1 && i > maxRetrials) {
15
+ throw Error('Too many retrials');
16
+ }
17
+ interval = intervalModifier(interval);
18
+ await sleep(interval);
19
+ }
20
+ return isReady;
21
+ })();
22
+ }
23
+ export const expandDottedPaths = (obj) => {
24
+ const settings = [];
25
+ for (let key in obj) {
26
+ const parsed = expandPath(key.split('.'), obj[key]);
27
+ settings.push(parsed);
28
+ }
29
+ return mergeWith({}, ...settings);
30
+ };
31
+ /**
32
+ * The docs for many language servers show settings in the
33
+ * VSCode format, e.g.: "pyls.plugins.pyflakes.enabled"
34
+ *
35
+ * VSCode converts that dot notation to JSON behind the scenes,
36
+ * as the language servers themselves don't accept that syntax.
37
+ */
38
+ export const expandPath = (path, value) => {
39
+ const obj = Object.create(null);
40
+ let curr = obj;
41
+ path.forEach((prop, i) => {
42
+ curr[prop] = Object.create(null);
43
+ if (i === path.length - 1) {
44
+ curr[prop] = value;
45
+ }
46
+ else {
47
+ curr = curr[prop];
48
+ }
49
+ });
50
+ return obj;
51
+ };
52
+ export class DefaultMap extends Map {
53
+ constructor(defaultFactory, entries) {
54
+ super(entries);
55
+ this.defaultFactory = defaultFactory;
56
+ }
57
+ get(k) {
58
+ return this.getOrCreate(k);
59
+ }
60
+ getOrCreate(k, ...args) {
61
+ if (this.has(k)) {
62
+ return super.get(k);
63
+ }
64
+ else {
65
+ let v = this.defaultFactory(k, ...args);
66
+ this.set(k, v);
67
+ return v;
68
+ }
69
+ }
70
+ }
71
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAe;IACzC,OAAO,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;QACjC,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,OAAO,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,OAAyB,EACzB,cAAsB,EAAE,EACxB,QAAQ,GAAG,EAAE,EACb,mBAAmB,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC;IAEnC,OAAO,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,OAAO,OAAO,EAAE,KAAK,IAAI,EAAE;YACzB,CAAC,IAAI,CAAC,CAAC;YACP,IAAI,WAAW,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,EAAE;gBACzC,MAAM,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAClC;YACD,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;SACvB;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,GAAuB,EACH,EAAE;IACtB,MAAM,QAAQ,GAAQ,EAAE,CAAC;IACzB,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE;QACnB,MAAM,MAAM,GAAG,UAAU,CAAC,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CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;YACxC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACf,OAAO,CAAC,CAAC;SACV;IACH,CAAC;CACF"}
@@ -0,0 +1,270 @@
1
+ import { IDocumentInfo } from 'lsp-ws-connection';
2
+ import { CodeEditor } from '@jupyterlab/codeeditor';
3
+ import { CellType } from '@jupyterlab/nbformat';
4
+ import { Signal } from '@lumino/signaling';
5
+ import { ILSPCodeExtractorsManager } from '../';
6
+ import { LanguageIdentifier } from '../lsp';
7
+ import { IEditorPosition, IRootPosition, ISourcePosition, IVirtualPosition } from '../positioning';
8
+ import { DefaultMap } from '../utils';
9
+ import type * as CodeMirror from 'codemirror';
10
+ declare type IRange = CodeEditor.IRange;
11
+ declare type language = string;
12
+ interface IVirtualLine {
13
+ /**
14
+ * Inspections for which document should be skipped for this virtual line?
15
+ */
16
+ skipInspect: Array<VirtualDocument.idPath>;
17
+ /**
18
+ * Where does the virtual line belongs to in the source document?
19
+ */
20
+ sourceLine: number | null;
21
+ editor: CodeEditor.IEditor;
22
+ }
23
+ export interface ICodeBlockOptions {
24
+ ceEditor: CodeEditor.IEditor;
25
+ value: string;
26
+ type: CellType;
27
+ }
28
+ export interface IVirtualDocumentBlock {
29
+ /**
30
+ * Line corresponding to the block in the entire foreign document
31
+ */
32
+ virtualLine: number;
33
+ virtualDocument: VirtualDocument;
34
+ editor: CodeEditor.IEditor;
35
+ }
36
+ export declare type ForeignDocumentsMap = Map<IRange, IVirtualDocumentBlock>;
37
+ interface ISourceLine {
38
+ virtualLine: number;
39
+ editor: CodeEditor.IEditor;
40
+ editorLine: number;
41
+ editorShift: CodeEditor.IPosition;
42
+ /**
43
+ * Everything which is not in the range of foreign documents belongs to the host.
44
+ */
45
+ foreignDocumentsMap: ForeignDocumentsMap;
46
+ }
47
+ export interface IForeignContext {
48
+ foreignDocument: VirtualDocument;
49
+ parentHost: VirtualDocument;
50
+ }
51
+ /**
52
+ * Check if given position is within range.
53
+ * Both start and end are inclusive.
54
+ * @param position
55
+ * @param range
56
+ */
57
+ export declare function isWithinRange(position: CodeEditor.IPosition, range: CodeEditor.IRange): boolean;
58
+ /**
59
+ * a virtual implementation of IDocumentInfo
60
+ */
61
+ export declare class VirtualDocumentInfo implements IDocumentInfo {
62
+ private _document;
63
+ version: number;
64
+ constructor(document: VirtualDocument);
65
+ get text(): string;
66
+ get uri(): string;
67
+ get languageId(): string;
68
+ }
69
+ export declare namespace VirtualDocument {
70
+ interface IOptions {
71
+ language: LanguageIdentifier;
72
+ foreignCodeExtractors: ILSPCodeExtractorsManager;
73
+ path: string;
74
+ fileExtension: string | undefined;
75
+ /**
76
+ * Notebooks or any other aggregates of documents are not supported
77
+ * by the LSP specification, and we need to make appropriate
78
+ * adjustments for them, pretending they are simple files
79
+ * so that the LSP servers do not refuse to cooperate.
80
+ */
81
+ hasLspSupportedFile: boolean;
82
+ /**
83
+ * Being standalone is relevant to foreign documents
84
+ * and defines whether following chunks of code in the same
85
+ * language should be appended to this document (false, not standalone)
86
+ * or should be considered separate documents (true, standalone)
87
+ *
88
+ */
89
+ standalone?: boolean;
90
+ parent?: VirtualDocument;
91
+ }
92
+ }
93
+ /**
94
+ * A notebook can hold one or more virtual documents; there is always one,
95
+ * "root" document, corresponding to the language of the kernel. All other
96
+ * virtual documents are extracted out of the notebook, based on magics,
97
+ * or other syntax constructs, depending on the kernel language.
98
+ *
99
+ * Virtual documents represent the underlying code in a single language,
100
+ * which has been parsed excluding interactive kernel commands (magics)
101
+ * which could be misunderstood by the specific LSP server.
102
+ *
103
+ * VirtualDocument has no awareness of the notebook or editor it lives in,
104
+ * however it is able to transform its content back to the notebook space,
105
+ * as it keeps editor coordinates for each virtual line.
106
+ *
107
+ * The notebook/editor aware transformations are preferred to be placed in
108
+ * VirtualEditor descendants rather than here.
109
+ *
110
+ * No dependency on editor implementation (such as CodeMirrorEditor)
111
+ * is allowed for VirtualEditor.
112
+ */
113
+ export declare class VirtualDocument {
114
+ language: string;
115
+ standalone: boolean;
116
+ isDisposed: boolean;
117
+ blankLinesBetweenCells: number;
118
+ lastSourceLine: number;
119
+ foreignDocumentClosed: Signal<VirtualDocument, IForeignContext>;
120
+ foreignDocumentOpened: Signal<VirtualDocument, IForeignContext>;
121
+ lastVirtualLine: number;
122
+ /**
123
+ * the remote document uri, version and other server-related info
124
+ */
125
+ documentInfo: IDocumentInfo;
126
+ /**
127
+ * Virtual lines keep all the lines present in the document AND extracted to the foreign document.
128
+ */
129
+ virtualLines: Map<number, IVirtualLine>;
130
+ changed: Signal<VirtualDocument, VirtualDocument>;
131
+ path: string;
132
+ fileExtension: string | undefined;
133
+ hasLspSupportedFile: boolean;
134
+ parent?: VirtualDocument | null;
135
+ updateManager: UpdateManager;
136
+ foreignDocuments: Map<VirtualDocument.virtualId, VirtualDocument>;
137
+ readonly instanceId: number;
138
+ protected sourceLines: Map<number, ISourceLine>;
139
+ protected lineBlocks: Array<string>;
140
+ protected unusedDocuments: Set<VirtualDocument>;
141
+ protected unusedStandaloneDocuments: DefaultMap<language, Array<VirtualDocument>>;
142
+ private _remainingLifetime;
143
+ private _editorToSourceLine;
144
+ private _editorToSourceLineNew;
145
+ private _foreignCodeExtractors;
146
+ private previousValue;
147
+ private static instancesCount;
148
+ private readonly options;
149
+ constructor(options: VirtualDocument.IOptions);
150
+ dispose(): void;
151
+ /**
152
+ * When this counter goes down to 0, the document will be destroyed and the associated connection will be closed;
153
+ * This is meant to reduce the number of open connections when a a foreign code snippet was removed from the document.
154
+ *
155
+ * Note: top level virtual documents are currently immortal (unless killed by other means); it might be worth
156
+ * implementing culling of unused documents, but if and only if JupyterLab will also implement culling of
157
+ * idle kernels - otherwise the user experience could be a bit inconsistent, and we would need to invent our own rules.
158
+ */
159
+ protected get remainingLifetime(): number;
160
+ protected set remainingLifetime(value: number);
161
+ clear(): void;
162
+ documentAtSourcePosition(position: ISourcePosition): VirtualDocument;
163
+ isWithinForeign(sourcePosition: ISourcePosition): boolean;
164
+ transformFromEditorToRoot(editor: CodeEditor.IEditor, position: IEditorPosition): IRootPosition | null;
165
+ virtualPositionAtDocument(sourcePosition: ISourcePosition): IVirtualPosition;
166
+ appendCodeBlock(block: ICodeBlockOptions, editorShift?: CodeEditor.IPosition, virtualShift?: CodeEditor.IPosition): void;
167
+ prepareCodeBlock(block: ICodeBlockOptions, editorShift?: CodeEditor.IPosition): {
168
+ lines: string[];
169
+ foreignDocumentsMap: Map<CodeEditor.IRange, IVirtualDocumentBlock>;
170
+ };
171
+ extractForeignCode(block: ICodeBlockOptions, editorShift: CodeEditor.IPosition): {
172
+ cellCodeKept: string;
173
+ foreignDocumentsMap: Map<CodeEditor.IRange, IVirtualDocumentBlock>;
174
+ };
175
+ private chooseForeignDocument;
176
+ private openForeign;
177
+ private forwardClosedSignal;
178
+ private forwardOpenedSignal;
179
+ closeForeign(document: VirtualDocument): void;
180
+ closeAllForeignDocuments(): void;
181
+ get value(): string;
182
+ get lastLine(): string;
183
+ closeExpiredDocuments(): void;
184
+ get virtualId(): VirtualDocument.virtualId;
185
+ get ancestry(): Array<VirtualDocument>;
186
+ get idPath(): VirtualDocument.idPath;
187
+ get uri(): VirtualDocument.uri;
188
+ transformSourceToEditor(pos: ISourcePosition): IEditorPosition;
189
+ /**
190
+ Can be null because some lines are added as padding/anchors
191
+ to the virtual document and those do not exist in the source document
192
+ and thus they are absent in the editor.
193
+ */
194
+ transformVirtualToEditor(virtualPosition: IVirtualPosition): IEditorPosition | null;
195
+ /**
196
+ Can be null because some lines are added as padding/anchors
197
+ to the virtual document and those do not exist in the source document.
198
+ */
199
+ transformVirtualToSource(position: IVirtualPosition): ISourcePosition | null;
200
+ get root(): VirtualDocument;
201
+ getEditorAtVirtualLine(pos: IVirtualPosition): CodeEditor.IEditor;
202
+ getEditorAtSourceLine(pos: ISourcePosition): CodeEditor.IEditor;
203
+ /**
204
+ * Recursively emits changed signal from the document or any descendant foreign document.
205
+ */
206
+ maybeEmitChanged(): void;
207
+ static ceToCm(position: CodeEditor.IPosition): CodeMirror.Position;
208
+ }
209
+ export declare namespace VirtualDocument {
210
+ /**
211
+ * Identifier composed of `virtual_id`s of a nested structure of documents,
212
+ * used to aide assignment of the connection to the virtual document
213
+ * handling specific, nested language usage; it will be appended to the file name
214
+ * when creating a connection.
215
+ */
216
+ type idPath = string;
217
+ /**
218
+ * Instance identifier for standalone documents (snippets), or language identifier
219
+ * for documents which should be interpreted as one when stretched across cells.
220
+ */
221
+ type virtualId = string;
222
+ /**
223
+ * Identifier composed of the file path and id_path.
224
+ */
225
+ type uri = string;
226
+ }
227
+ export declare function collectDocuments(virtualDocument: VirtualDocument): Set<VirtualDocument>;
228
+ export interface IBlockAddedInfo {
229
+ virtualDocument: VirtualDocument;
230
+ block: ICodeBlockOptions;
231
+ }
232
+ export declare class UpdateManager {
233
+ private virtualDocument;
234
+ /**
235
+ * Virtual documents update guard.
236
+ */
237
+ private isUpdateInProgress;
238
+ private updateLock;
239
+ protected isDisposed: boolean;
240
+ /**
241
+ * Signal emitted by the editor that triggered the update, providing the root document of the updated documents.
242
+ */
243
+ private documentUpdated;
244
+ blockAdded: Signal<UpdateManager, IBlockAddedInfo>;
245
+ updateDone: Promise<void>;
246
+ updateBegan: Signal<UpdateManager, ICodeBlockOptions[]>;
247
+ updateFinished: Signal<UpdateManager, ICodeBlockOptions[]>;
248
+ constructor(virtualDocument: VirtualDocument);
249
+ dispose(): void;
250
+ /**
251
+ * Once all the foreign documents were refreshed, the unused documents (and their connections)
252
+ * should be terminated if their lifetime has expired.
253
+ */
254
+ private onUpdated;
255
+ private canUpdate;
256
+ /**
257
+ * Execute provided callback within an update-locked context, which guarantees that:
258
+ * - the previous updates must have finished before the callback call, and
259
+ * - no update will happen when executing the callback
260
+ * @param fn - the callback to execute in update lock
261
+ */
262
+ withUpdateLock(fn: () => void): Promise<void>;
263
+ /**
264
+ * Update all the virtual documents, emit documents updated with root document if succeeded,
265
+ * and resolve a void promise. The promise does not contain the text value of the root document,
266
+ * as to avoid an easy trap of ignoring the changes in the virtual documents.
267
+ */
268
+ updateDocuments(blocks: ICodeBlockOptions[]): Promise<void>;
269
+ }
270
+ export {};