@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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/adapters/adapter.d.ts +255 -0
- package/es/adapters/adapter.d.ts.map +1 -0
- package/es/adapters/adapter.js +647 -0
- package/es/adapters/notebook-adapter.d.ts +150 -0
- package/es/adapters/notebook-adapter.d.ts.map +1 -0
- package/es/adapters/notebook-adapter.js +588 -0
- package/es/adapters/status-message.d.ts +48 -0
- package/es/adapters/status-message.d.ts.map +1 -0
- package/es/adapters/status-message.js +110 -0
- package/es/connection-manager.d.ts +199 -0
- package/es/connection-manager.d.ts.map +1 -0
- package/es/connection-manager.js +685 -0
- package/es/connection.d.ts +149 -0
- package/es/connection.d.ts.map +1 -0
- package/es/connection.js +591 -0
- package/es/extractors/index.d.ts +4 -0
- package/es/extractors/index.d.ts.map +1 -0
- package/es/extractors/index.js +6 -0
- package/es/extractors/manager.d.ts +31 -0
- package/es/extractors/manager.d.ts.map +1 -0
- package/es/extractors/manager.js +90 -0
- package/es/extractors/text-extractor.d.ts +56 -0
- package/es/extractors/text-extractor.d.ts.map +1 -0
- package/es/extractors/text-extractor.js +72 -0
- package/es/extractors/types.d.ts +68 -0
- package/es/extractors/types.d.ts.map +1 -0
- package/es/extractors/types.js +1 -0
- package/es/feature.d.ts +29 -0
- package/es/feature.d.ts.map +1 -0
- package/es/feature.js +85 -0
- package/es/index.d.ts +19 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +21 -0
- package/es/lsp-app-contribution.d.ts +19 -0
- package/es/lsp-app-contribution.d.ts.map +1 -0
- package/es/lsp-app-contribution.js +155 -0
- package/es/lsp-protocol.d.ts +10 -0
- package/es/lsp-protocol.d.ts.map +1 -0
- package/es/lsp-protocol.js +1 -0
- package/es/lsp.d.ts +136 -0
- package/es/lsp.d.ts.map +1 -0
- package/es/lsp.js +141 -0
- package/es/manager.d.ts +142 -0
- package/es/manager.d.ts.map +1 -0
- package/es/manager.js +423 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +21 -0
- package/es/plugin.d.ts +56 -0
- package/es/plugin.d.ts.map +1 -0
- package/es/plugin.js +0 -0
- package/es/positioning.d.ts +66 -0
- package/es/positioning.d.ts.map +1 -0
- package/es/positioning.js +96 -0
- package/es/schema.d.ts +240 -0
- package/es/schema.d.ts.map +1 -0
- package/es/schema.js +0 -0
- package/es/tokens.d.ts +677 -0
- package/es/tokens.d.ts.map +1 -0
- package/es/tokens.js +183 -0
- package/es/utils.d.ts +33 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +168 -0
- package/es/virtual/document.d.ts +546 -0
- package/es/virtual/document.d.ts.map +1 -0
- package/es/virtual/document.js +1263 -0
- package/es/ws-connection/server-capability-registration.d.ts +19 -0
- package/es/ws-connection/server-capability-registration.d.ts.map +1 -0
- package/es/ws-connection/server-capability-registration.js +51 -0
- package/es/ws-connection/types.d.ts +76 -0
- package/es/ws-connection/types.d.ts.map +1 -0
- package/es/ws-connection/types.js +1 -0
- package/es/ws-connection/ws-connection.d.ts +105 -0
- package/es/ws-connection/ws-connection.d.ts.map +1 -0
- package/es/ws-connection/ws-connection.js +301 -0
- package/package.json +67 -0
- package/src/adapters/adapter.ts +611 -0
- package/src/adapters/notebook-adapter.ts +463 -0
- package/src/adapters/status-message.ts +93 -0
- package/src/connection-manager.ts +626 -0
- package/src/connection.ts +570 -0
- package/src/extractors/index.ts +6 -0
- package/src/extractors/manager.ts +82 -0
- package/src/extractors/text-extractor.ts +94 -0
- package/src/extractors/types.ts +78 -0
- package/src/feature.ts +60 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +21 -0
- package/src/lsp-app-contribution.ts +83 -0
- package/src/lsp-protocol.ts +10 -0
- package/src/lsp.ts +160 -0
- package/src/manager.ts +358 -0
- package/src/module.ts +32 -0
- package/src/plugin.ts +62 -0
- package/src/positioning.ts +121 -0
- package/src/schema.ts +249 -0
- package/src/tokens.ts +843 -0
- package/src/utils.ts +109 -0
- package/src/virtual/document.ts +1250 -0
- package/src/ws-connection/server-capability-registration.ts +77 -0
- package/src/ws-connection/types.ts +102 -0
- package/src/ws-connection/ws-connection.ts +320 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
// Copyright (c) Jupyter Development Team.
|
|
4
|
+
// Distributed under the terms of the Modified BSD License.
|
|
5
|
+
|
|
6
|
+
import type { ReadonlyJSONObject, ReadonlyJSONValue } from '@difizen/libro-common';
|
|
7
|
+
import mergeWith from 'lodash.mergewith';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Helper to wait for timeout.
|
|
11
|
+
*
|
|
12
|
+
* @param timeout - time out in ms
|
|
13
|
+
*/
|
|
14
|
+
export async function sleep(timeout: number): Promise<void> {
|
|
15
|
+
return new Promise<void>((resolve) => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
resolve();
|
|
18
|
+
}, timeout);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Wait for an event by pooling the `isReady` function.
|
|
24
|
+
*/
|
|
25
|
+
export function untilReady(
|
|
26
|
+
isReady: CallableFunction,
|
|
27
|
+
maxRetrials = 35,
|
|
28
|
+
interval = 50,
|
|
29
|
+
intervalModifier = (i: number) => i,
|
|
30
|
+
): Promise<CallableFunction> {
|
|
31
|
+
return (async () => {
|
|
32
|
+
let i = 0;
|
|
33
|
+
while (isReady() !== true) {
|
|
34
|
+
i += 1;
|
|
35
|
+
if (maxRetrials !== -1 && i > maxRetrials) {
|
|
36
|
+
throw Error('Too many retrials');
|
|
37
|
+
}
|
|
38
|
+
interval = intervalModifier(interval);
|
|
39
|
+
await sleep(interval);
|
|
40
|
+
}
|
|
41
|
+
return isReady;
|
|
42
|
+
})();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Convert dotted path into dictionary.
|
|
47
|
+
*/
|
|
48
|
+
export function expandDottedPaths(obj: ReadonlyJSONObject): ReadonlyJSONObject {
|
|
49
|
+
const settings: any = [];
|
|
50
|
+
for (const key in obj) {
|
|
51
|
+
const parsed = expandPath(key.split('.'), obj[key]);
|
|
52
|
+
settings.push(parsed);
|
|
53
|
+
}
|
|
54
|
+
return mergeWith({}, ...settings);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The docs for many language servers show settings in the
|
|
59
|
+
* VSCode format, e.g.: "pyls.plugins.pyflakes.enabled"
|
|
60
|
+
*
|
|
61
|
+
* VSCode converts that dot notation to JSON behind the scenes,
|
|
62
|
+
* as the language servers themselves don't accept that syntax.
|
|
63
|
+
*/
|
|
64
|
+
export const expandPath = (
|
|
65
|
+
path: string[],
|
|
66
|
+
value: ReadonlyJSONValue,
|
|
67
|
+
): ReadonlyJSONObject => {
|
|
68
|
+
const obj: any = Object.create(null);
|
|
69
|
+
|
|
70
|
+
let curr = obj;
|
|
71
|
+
path.forEach((prop: string, i: any) => {
|
|
72
|
+
curr[prop] = Object.create(null);
|
|
73
|
+
|
|
74
|
+
if (i === path.length - 1) {
|
|
75
|
+
curr[prop] = value;
|
|
76
|
+
} else {
|
|
77
|
+
curr = curr[prop];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return obj;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* An extended map which will create value for key on the fly.
|
|
86
|
+
*/
|
|
87
|
+
export class DefaultMap<K, V> extends Map<K, V> {
|
|
88
|
+
constructor(
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/parameter-properties, @typescript-eslint/no-parameter-properties
|
|
90
|
+
protected defaultFactory: (...args: any[]) => V,
|
|
91
|
+
entries?: readonly (readonly [K, V])[] | null,
|
|
92
|
+
) {
|
|
93
|
+
super(entries);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override get(k: K): V {
|
|
97
|
+
return this.getOrCreate(k);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getOrCreate(k: K, ...args: any[]): V {
|
|
101
|
+
if (this.has(k)) {
|
|
102
|
+
return super.get(k)!;
|
|
103
|
+
} else {
|
|
104
|
+
const v = this.defaultFactory(k, ...args);
|
|
105
|
+
this.set(k, v);
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|