@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.
- package/lib/adapters/adapter.d.ts +125 -0
- package/lib/adapters/adapter.js +382 -0
- package/lib/adapters/adapter.js.map +1 -0
- package/lib/connection.d.ts +65 -0
- package/lib/connection.js +309 -0
- package/lib/connection.js.map +1 -0
- package/lib/connection_manager.d.ts +71 -0
- package/lib/connection_manager.js +312 -0
- package/lib/connection_manager.js.map +1 -0
- package/lib/extractors/manager.d.ts +13 -0
- package/lib/extractors/manager.js +44 -0
- package/lib/extractors/manager.js.map +1 -0
- package/lib/extractors/text_extractor.d.ts +28 -0
- package/lib/extractors/text_extractor.js +27 -0
- package/lib/extractors/text_extractor.js.map +1 -0
- package/lib/extractors/types.d.ts +65 -0
- package/lib/extractors/types.js +2 -0
- package/lib/extractors/types.js.map +1 -0
- package/lib/feature.d.ts +11 -0
- package/lib/feature.js +31 -0
- package/lib/feature.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -0
- package/lib/lsp.d.ts +129 -0
- package/lib/lsp.js +125 -0
- package/lib/lsp.js.map +1 -0
- package/lib/manager.d.ts +29 -0
- package/lib/manager.js +130 -0
- package/lib/manager.js.map +1 -0
- package/lib/plugin.d.ts +45 -0
- package/lib/plugin.js +3 -0
- package/lib/plugin.js.map +1 -0
- package/lib/positioning.d.ts +28 -0
- package/lib/positioning.js +49 -0
- package/lib/positioning.js.map +1 -0
- package/lib/schema.d.ts +228 -0
- package/lib/schema.js +3 -0
- package/lib/schema.js.map +1 -0
- package/lib/tokens.d.ts +368 -0
- package/lib/tokens.js +58 -0
- package/lib/tokens.js.map +1 -0
- package/lib/utils.d.ts +18 -0
- package/lib/utils.js +71 -0
- package/lib/utils.js.map +1 -0
- package/lib/virtual/document.d.ts +270 -0
- package/lib/virtual/document.js +600 -0
- package/lib/virtual/document.js.map +1 -0
- package/package.json +75 -0
- package/style/index.css +11 -0
- package/style/index.js +11 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
2
|
+
import { Signal } from '@lumino/signaling';
|
|
3
|
+
import { LSPConnection } from './connection';
|
|
4
|
+
import { expandDottedPaths, sleep, untilReady } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
* Each Widget with a document (whether file or a notebook) has the same DocumentConnectionManager
|
|
7
|
+
* (see JupyterLabWidgetAdapter). Using id_path instead of uri led to documents being overwritten
|
|
8
|
+
* as two identical id_paths could be created for two different notebooks.
|
|
9
|
+
*/
|
|
10
|
+
export class DocumentConnectionManager {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
/**
|
|
13
|
+
* Fired the first time a connection is opened. These _should_ be the only
|
|
14
|
+
* invocation of `.on` (once remaining LSPFeature.connection_handlers are made
|
|
15
|
+
* singletons).
|
|
16
|
+
*/
|
|
17
|
+
this.onNewConnection = (connection) => {
|
|
18
|
+
connection.on('error', e => {
|
|
19
|
+
console.error(e);
|
|
20
|
+
// TODO invalid now
|
|
21
|
+
let error = e.length && e.length >= 1 ? e[0] : new Error();
|
|
22
|
+
// TODO: those codes may be specific to my proxy client, need to investigate
|
|
23
|
+
if (error.message.indexOf('code = 1005') !== -1) {
|
|
24
|
+
console.error(`Connection failed for ${connection}`);
|
|
25
|
+
this.forEachDocumentOfConnection(connection, virtualDocument => {
|
|
26
|
+
console.error('disconnecting ' + virtualDocument.uri);
|
|
27
|
+
this.closed.emit({ connection, virtualDocument });
|
|
28
|
+
this.ignoredLanguages.add(virtualDocument.language);
|
|
29
|
+
console.error(`Cancelling further attempts to connect ${virtualDocument.uri} and other documents for this language (no support from the server)`);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (error.message.indexOf('code = 1006') !== -1) {
|
|
33
|
+
console.error('Connection closed by the server');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.error('Connection error:', e);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
connection.on('serverInitialized', capabilities => {
|
|
40
|
+
// Initialize using settings stored in the SettingRegistry
|
|
41
|
+
this.forEachDocumentOfConnection(connection, virtualDocument => {
|
|
42
|
+
// TODO: is this still necessary, e.g. for status bar to update responsively?
|
|
43
|
+
this.initialized.emit({ connection, virtualDocument });
|
|
44
|
+
});
|
|
45
|
+
this.updateServerConfigurations(this.initialConfigurations);
|
|
46
|
+
});
|
|
47
|
+
connection.on('close', closedManually => {
|
|
48
|
+
if (!closedManually) {
|
|
49
|
+
console.error('Connection unexpectedly disconnected');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log('Connection closed');
|
|
53
|
+
this.forEachDocumentOfConnection(connection, virtualDocument => {
|
|
54
|
+
this.closed.emit({ connection, virtualDocument });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
this.connections = new Map();
|
|
60
|
+
this.documents = new Map();
|
|
61
|
+
this.adapters = new Map();
|
|
62
|
+
this.ignoredLanguages = new Set();
|
|
63
|
+
this.connected = new Signal(this);
|
|
64
|
+
this.initialized = new Signal(this);
|
|
65
|
+
this.disconnected = new Signal(this);
|
|
66
|
+
this.closed = new Signal(this);
|
|
67
|
+
this.documentsChanged = new Signal(this);
|
|
68
|
+
this.languageServerManager = options.languageServerManager;
|
|
69
|
+
Private.setLanguageServerManager(options.languageServerManager);
|
|
70
|
+
}
|
|
71
|
+
connectDocumentSignals(virtualDocument) {
|
|
72
|
+
virtualDocument.foreignDocumentOpened.connect(this.onForeignDocumentOpened, this);
|
|
73
|
+
virtualDocument.foreignDocumentClosed.connect(this.onForeignDocumentClosed, this);
|
|
74
|
+
this.documents.set(virtualDocument.uri, virtualDocument);
|
|
75
|
+
this.documentsChanged.emit(this.documents);
|
|
76
|
+
}
|
|
77
|
+
disconnectDocumentSignals(virtualDocument, emit = true) {
|
|
78
|
+
virtualDocument.foreignDocumentOpened.disconnect(this.onForeignDocumentOpened, this);
|
|
79
|
+
virtualDocument.foreignDocumentClosed.disconnect(this.onForeignDocumentClosed, this);
|
|
80
|
+
this.documents.delete(virtualDocument.uri);
|
|
81
|
+
for (const foreign of virtualDocument.foreignDocuments.values()) {
|
|
82
|
+
this.disconnectDocumentSignals(foreign, false);
|
|
83
|
+
}
|
|
84
|
+
if (emit) {
|
|
85
|
+
this.documentsChanged.emit(this.documents);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
onForeignDocumentOpened(_host, context) {
|
|
89
|
+
console.log('ConnectionManager received foreign document: ', context.foreignDocument.uri);
|
|
90
|
+
}
|
|
91
|
+
onForeignDocumentClosed(_host, context) {
|
|
92
|
+
const { foreignDocument } = context;
|
|
93
|
+
this.unregisterDocument(foreignDocument, false);
|
|
94
|
+
this.disconnectDocumentSignals(foreignDocument);
|
|
95
|
+
}
|
|
96
|
+
async connectSocket(options) {
|
|
97
|
+
let { language, capabilities, virtualDocument } = options;
|
|
98
|
+
this.connectDocumentSignals(virtualDocument);
|
|
99
|
+
const uris = DocumentConnectionManager.solveUris(virtualDocument, language);
|
|
100
|
+
const matchingServers = this.languageServerManager.getMatchingServers({
|
|
101
|
+
language
|
|
102
|
+
});
|
|
103
|
+
console.debug('Matching servers: ', matchingServers);
|
|
104
|
+
// for now use only the server with the highest priority.
|
|
105
|
+
const languageServerId = matchingServers.length === 0 ? null : matchingServers[0];
|
|
106
|
+
// lazily load 1) the underlying library (1.5mb) and/or 2) a live WebSocket-
|
|
107
|
+
// like connection: either already connected or potentially in the process
|
|
108
|
+
// of connecting.
|
|
109
|
+
const connection = await Private.connection(language, languageServerId, uris, this.onNewConnection, capabilities);
|
|
110
|
+
// if connecting for the first time, all documents subsequent documents will
|
|
111
|
+
// be re-opened and synced
|
|
112
|
+
this.connections.set(virtualDocument.uri, connection);
|
|
113
|
+
return connection;
|
|
114
|
+
}
|
|
115
|
+
registerAdapter(path, adapter) {
|
|
116
|
+
this.adapters.set(path, adapter);
|
|
117
|
+
adapter.widget.disposed.connect(() => {
|
|
118
|
+
this.adapters.delete(path);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
updateConfiguration(allServerSettings) {
|
|
122
|
+
this.languageServerManager.setConfiguration(allServerSettings);
|
|
123
|
+
}
|
|
124
|
+
updateServerConfigurations(allServerSettings) {
|
|
125
|
+
let languageServerId;
|
|
126
|
+
for (languageServerId in allServerSettings) {
|
|
127
|
+
if (!allServerSettings.hasOwnProperty(languageServerId)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const rawSettings = allServerSettings[languageServerId];
|
|
131
|
+
const parsedSettings = expandDottedPaths(rawSettings.serverSettings || {});
|
|
132
|
+
const serverSettings = {
|
|
133
|
+
settings: parsedSettings
|
|
134
|
+
};
|
|
135
|
+
Private.updateServerConfiguration(languageServerId, serverSettings);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* TODO: presently no longer referenced. A failing connection would close
|
|
140
|
+
* the socket, triggering the language server on the other end to exit
|
|
141
|
+
*/
|
|
142
|
+
async retryToConnect(options, reconnectDelay, retrialsLeft = -1) {
|
|
143
|
+
let { virtualDocument } = options;
|
|
144
|
+
if (this.ignoredLanguages.has(virtualDocument.language)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
let interval = reconnectDelay * 1000;
|
|
148
|
+
let success = false;
|
|
149
|
+
while (retrialsLeft !== 0 && !success) {
|
|
150
|
+
await this.connect(options)
|
|
151
|
+
.then(() => {
|
|
152
|
+
success = true;
|
|
153
|
+
})
|
|
154
|
+
.catch(e => {
|
|
155
|
+
console.warn(e);
|
|
156
|
+
});
|
|
157
|
+
console.log('will attempt to re-connect in ' + interval / 1000 + ' seconds');
|
|
158
|
+
await sleep(interval);
|
|
159
|
+
// gradually increase the time delay, up to 5 sec
|
|
160
|
+
interval = interval < 5 * 1000 ? interval + 500 : interval;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
disconnect(languageId) {
|
|
164
|
+
Private.disconnect(languageId);
|
|
165
|
+
}
|
|
166
|
+
// async registerDocument(options: IDocumentRegistationOptions) {}
|
|
167
|
+
async connect(options, firstTimeoutSeconds = 30, secondTimeoutMinutes = 5) {
|
|
168
|
+
let connection = await this.connectSocket(options);
|
|
169
|
+
let { virtualDocument } = options;
|
|
170
|
+
if (!connection.isReady) {
|
|
171
|
+
try {
|
|
172
|
+
// user feedback hinted that 40 seconds was too short and some users are willing to wait more;
|
|
173
|
+
// to make the best of both worlds we first check frequently (6.6 times a second) for the first
|
|
174
|
+
// 30 seconds, and show the warning early in case if something is wrong; we then continue retrying
|
|
175
|
+
// for another 5 minutes, but only once per second.
|
|
176
|
+
await untilReady(() => connection.isReady, Math.round((firstTimeoutSeconds * 1000) / 150), 150);
|
|
177
|
+
}
|
|
178
|
+
catch (_a) {
|
|
179
|
+
console.log(`Connection to ${virtualDocument.uri} timed out after ${firstTimeoutSeconds} seconds, will continue retrying for another ${secondTimeoutMinutes} minutes`);
|
|
180
|
+
try {
|
|
181
|
+
await untilReady(() => connection.isReady, 60 * secondTimeoutMinutes, 1000);
|
|
182
|
+
}
|
|
183
|
+
catch (_b) {
|
|
184
|
+
console.log(`Connection to ${virtualDocument.uri} timed out again after ${secondTimeoutMinutes} minutes, giving up`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
this.connected.emit({ connection, virtualDocument });
|
|
190
|
+
return connection;
|
|
191
|
+
}
|
|
192
|
+
unregisterDocument(virtualDocument, emit = true) {
|
|
193
|
+
const connection = this.connections.get(virtualDocument.uri);
|
|
194
|
+
if (connection) {
|
|
195
|
+
this.connections.delete(virtualDocument.uri);
|
|
196
|
+
const allConnection = new Set(this.connections.values());
|
|
197
|
+
if (!allConnection.has(connection)) {
|
|
198
|
+
this.disconnect(connection.serverIdentifier);
|
|
199
|
+
}
|
|
200
|
+
if (emit) {
|
|
201
|
+
this.documentsChanged.emit(this.documents);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
updateLogging(logAllCommunication, setTrace) {
|
|
206
|
+
for (const connection of this.connections.values()) {
|
|
207
|
+
connection.logAllCommunication = logAllCommunication;
|
|
208
|
+
if (setTrace !== null) {
|
|
209
|
+
connection.clientNotifications['$/setTrace'].emit({ value: setTrace });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
forEachDocumentOfConnection(connection, callback) {
|
|
214
|
+
for (const [virtualDocumentUri, currentConnection] of this.connections.entries()) {
|
|
215
|
+
if (connection !== currentConnection) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
callback(this.documents.get(virtualDocumentUri));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
(function (DocumentConnectionManager) {
|
|
223
|
+
function solveUris(virtualDocument, language) {
|
|
224
|
+
const wsBase = PageConfig.getBaseUrl().replace(/^http/, 'ws');
|
|
225
|
+
const rootUri = PageConfig.getOption('rootUri');
|
|
226
|
+
const virtualDocumentsUri = PageConfig.getOption('virtualDocumentsUri');
|
|
227
|
+
const baseUri = virtualDocument.hasLspSupportedFile
|
|
228
|
+
? rootUri
|
|
229
|
+
: virtualDocumentsUri;
|
|
230
|
+
// for now take the best match only
|
|
231
|
+
const matchingServers = Private.getLanguageServerManager().getMatchingServers({
|
|
232
|
+
language
|
|
233
|
+
});
|
|
234
|
+
const languageServerId = matchingServers.length === 0 ? null : matchingServers[0];
|
|
235
|
+
if (languageServerId === null) {
|
|
236
|
+
throw `No language server installed for language ${language}`;
|
|
237
|
+
}
|
|
238
|
+
// workaround url-parse bug(s) (see https://github.com/jupyter-lsp/jupyterlab-lsp/issues/595)
|
|
239
|
+
let documentUri = URLExt.join(baseUri, virtualDocument.uri);
|
|
240
|
+
if (!documentUri.startsWith('file:///') &&
|
|
241
|
+
documentUri.startsWith('file://')) {
|
|
242
|
+
documentUri = documentUri.replace('file://', 'file:///');
|
|
243
|
+
if (documentUri.startsWith('file:///users/') &&
|
|
244
|
+
baseUri.startsWith('file:///Users/')) {
|
|
245
|
+
documentUri = documentUri.replace('file:///users/', 'file:///Users/');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
base: baseUri,
|
|
250
|
+
document: documentUri,
|
|
251
|
+
server: URLExt.join('ws://jupyter-lsp', language),
|
|
252
|
+
socket: URLExt.join(wsBase, 'lsp', 'ws', languageServerId)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
DocumentConnectionManager.solveUris = solveUris;
|
|
256
|
+
})(DocumentConnectionManager || (DocumentConnectionManager = {}));
|
|
257
|
+
/**
|
|
258
|
+
* Namespace primarily for language-keyed cache of LSPConnections
|
|
259
|
+
*/
|
|
260
|
+
var Private;
|
|
261
|
+
(function (Private) {
|
|
262
|
+
const _connections = new Map();
|
|
263
|
+
let _languageServerManager;
|
|
264
|
+
function getLanguageServerManager() {
|
|
265
|
+
return _languageServerManager;
|
|
266
|
+
}
|
|
267
|
+
Private.getLanguageServerManager = getLanguageServerManager;
|
|
268
|
+
function setLanguageServerManager(languageServerManager) {
|
|
269
|
+
_languageServerManager = languageServerManager;
|
|
270
|
+
}
|
|
271
|
+
Private.setLanguageServerManager = setLanguageServerManager;
|
|
272
|
+
function disconnect(languageServerId) {
|
|
273
|
+
const connection = _connections.get(languageServerId);
|
|
274
|
+
if (connection) {
|
|
275
|
+
connection.close();
|
|
276
|
+
_connections.delete(languageServerId);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
Private.disconnect = disconnect;
|
|
280
|
+
/**
|
|
281
|
+
* Return (or create and initialize) the WebSocket associated with the language
|
|
282
|
+
*/
|
|
283
|
+
async function connection(language, languageServerId, uris, onCreate, capabilities) {
|
|
284
|
+
let connection = _connections.get(languageServerId);
|
|
285
|
+
if (connection == null) {
|
|
286
|
+
const socket = new WebSocket(uris.socket);
|
|
287
|
+
const connection = new LSPConnection({
|
|
288
|
+
languageId: language,
|
|
289
|
+
serverUri: uris.server,
|
|
290
|
+
rootUri: uris.base,
|
|
291
|
+
serverIdentifier: languageServerId,
|
|
292
|
+
capabilities: capabilities
|
|
293
|
+
});
|
|
294
|
+
// TODO: remove remaining unbounded users of connection.on
|
|
295
|
+
connection.setMaxListeners(999);
|
|
296
|
+
_connections.set(languageServerId, connection);
|
|
297
|
+
connection.connect(socket);
|
|
298
|
+
onCreate(connection);
|
|
299
|
+
}
|
|
300
|
+
connection = _connections.get(languageServerId);
|
|
301
|
+
return connection;
|
|
302
|
+
}
|
|
303
|
+
Private.connection = connection;
|
|
304
|
+
function updateServerConfiguration(languageServerId, settings) {
|
|
305
|
+
const connection = _connections.get(languageServerId);
|
|
306
|
+
if (connection) {
|
|
307
|
+
connection.sendConfigurationChange(settings);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
Private.updateServerConfiguration = updateServerConfiguration;
|
|
311
|
+
})(Private || (Private = {}));
|
|
312
|
+
//# sourceMappingURL=connection_manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection_manager.js","sourceRoot":"","sources":["../src/connection_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAa7C,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI/D;;;;GAIG;AACH,MAAM,OAAO,yBAAyB;IA2BpC,YAAY,OAA2C;QA6IvD;;;;WAIG;QACH,oBAAe,GAAG,CAAC,UAAyB,EAAQ,EAAE;YACpD,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;gBACzB,OAAO,CAAC,KAAK,CAAC,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,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAG,IAAI,aAAa,CAAC;gBACnC,UAAU,EAAE,QAAQ;gBACpB,SAAS,EAAE,IAAI,CAAC,MAAM;gBACtB,OAAO,EAAE,IAAI,CAAC,IAAI;gBAClB,gBAAgB,EAAE,gBAAgB;gBAClC,YAAY,EAAE,YAAY;aAC3B,CAAC,CAAC;YACH,0DAA0D;YAC1D,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAChC,YAAY,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YAC/C,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC3B,QAAQ,CAAC,UAAU,CAAC,CAAC;SACtB;QAED,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAE,CAAC;QAEjD,OAAO,UAAU,CAAC;IACpB,CAAC;IA3BqB,kBAAU,aA2B/B,CAAA;IAED,SAAgB,yBAAyB,CACvC,gBAAmC,EACnC,QAA+C;QAE/C,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QACtD,IAAI,UAAU,EAAE;YACd,UAAU,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;SAC9C;IACH,CAAC;IARe,iCAAyB,4BAQxC,CAAA;AACH,CAAC,EA9DS,OAAO,KAAP,OAAO,QA8DhB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CellType } from '@jupyterlab/nbformat';
|
|
2
|
+
import { ILSPCodeExtractorsManager } from '../tokens';
|
|
3
|
+
import { IForeignCodeExtractor } from './types';
|
|
4
|
+
export declare class CodeExtractorsManager implements ILSPCodeExtractorsManager {
|
|
5
|
+
private _extractorMap;
|
|
6
|
+
private _extractorMapAnyLanguage;
|
|
7
|
+
constructor();
|
|
8
|
+
getExtractors(cellType: CellType, hostLanguage: string | null): IForeignCodeExtractor[];
|
|
9
|
+
/**
|
|
10
|
+
* Register an extractor to extract foreign code from host documents of specified language.
|
|
11
|
+
*/
|
|
12
|
+
register(extractor: IForeignCodeExtractor, hostLanguage: string | null): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class CodeExtractorsManager {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._extractorMap = new Map();
|
|
4
|
+
this._extractorMapAnyLanguage = new Map();
|
|
5
|
+
['code', 'markdown', 'raw'].forEach(cell => {
|
|
6
|
+
this._extractorMap.set(cell, new Map());
|
|
7
|
+
this._extractorMapAnyLanguage.set(cell, []);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
getExtractors(cellType, hostLanguage) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
if (hostLanguage) {
|
|
13
|
+
const currentMap = this._extractorMap.get(cellType);
|
|
14
|
+
return (_a = currentMap.get(hostLanguage)) !== null && _a !== void 0 ? _a : [];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return (_b = this._extractorMapAnyLanguage.get(cellType)) !== null && _b !== void 0 ? _b : [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register an extractor to extract foreign code from host documents of specified language.
|
|
22
|
+
*/
|
|
23
|
+
register(extractor, hostLanguage) {
|
|
24
|
+
const cellType = extractor.cellType;
|
|
25
|
+
if (hostLanguage) {
|
|
26
|
+
cellType.forEach(type => {
|
|
27
|
+
const currentMap = this._extractorMap.get(type);
|
|
28
|
+
const extractorList = currentMap.get(hostLanguage);
|
|
29
|
+
if (!extractorList) {
|
|
30
|
+
currentMap.set(hostLanguage, [extractor]);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
extractorList === null || extractorList === void 0 ? void 0 : extractorList.push(extractor);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
cellType.forEach(type => {
|
|
39
|
+
this._extractorMapAnyLanguage.get(type).push(extractor);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/extractors/manager.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,qBAAqB;IAGhC;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAGzB,CAAC;QAEJ,IAAI,CAAC,wBAAwB,GAAG,IAAI,GAAG,EAGpC,CAAC;QAEH,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACzD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YACxC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,aAAa,CACX,QAAkB,EAClB,YAA2B;;QAE3B,IAAI,YAAY,EAAE;YAChB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;YACrD,OAAO,MAAA,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,mCAAI,EAAE,CAAC;SAC3C;aAAM;YACL,OAAO,MAAA,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;SAC1D;IACH,CAAC;IAED;;OAEG;IACH,QAAQ,CACN,SAAgC,EAChC,YAA2B;QAE3B,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QACpC,IAAI,YAAY,EAAE;YAChB,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACtB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;gBACjD,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;gBACnD,IAAI,CAAC,aAAa,EAAE;oBAClB,UAAU,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;iBAC3C;qBAAM;oBACL,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAC,SAAS,CAAC,CAAC;iBAChC;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACtB,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3D,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CellType } from '@jupyterlab/nbformat';
|
|
2
|
+
import { LanguageIdentifier } from '../lsp';
|
|
3
|
+
import { IExtractedCode, IForeignCodeExtractor } from './types';
|
|
4
|
+
export declare class TextForeignCodeExtractor implements IForeignCodeExtractor {
|
|
5
|
+
language: LanguageIdentifier;
|
|
6
|
+
standalone: boolean;
|
|
7
|
+
fileExtension: string;
|
|
8
|
+
cellType: CellType[];
|
|
9
|
+
constructor(options: TextForeignCodeExtractor.IOptions);
|
|
10
|
+
hasForeignCode(code: string, cellType: CellType): boolean;
|
|
11
|
+
extractForeignCode(code: string): IExtractedCode[];
|
|
12
|
+
}
|
|
13
|
+
declare namespace TextForeignCodeExtractor {
|
|
14
|
+
interface IOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The foreign language.
|
|
17
|
+
*/
|
|
18
|
+
language: string;
|
|
19
|
+
/**
|
|
20
|
+
* Should the foreign code be appended (False) to the previously established virtual document of the same language,
|
|
21
|
+
* or is it standalone snippet which requires separate connection?
|
|
22
|
+
*/
|
|
23
|
+
isStandalone: boolean;
|
|
24
|
+
file_extension: string;
|
|
25
|
+
cellType: CellType[];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { positionAtOffset } from '../positioning';
|
|
2
|
+
export class TextForeignCodeExtractor {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.language = options.language;
|
|
5
|
+
this.standalone = options.isStandalone;
|
|
6
|
+
this.fileExtension = options.file_extension;
|
|
7
|
+
this.cellType = options.cellType;
|
|
8
|
+
}
|
|
9
|
+
hasForeignCode(code, cellType) {
|
|
10
|
+
return this.cellType.includes(cellType);
|
|
11
|
+
}
|
|
12
|
+
extractForeignCode(code) {
|
|
13
|
+
let lines = code.split('\n');
|
|
14
|
+
let extracts = new Array();
|
|
15
|
+
let foreignCodeFragment = code;
|
|
16
|
+
let start = positionAtOffset(0, lines);
|
|
17
|
+
let end = positionAtOffset(foreignCodeFragment.length, lines);
|
|
18
|
+
extracts.push({
|
|
19
|
+
hostCode: '',
|
|
20
|
+
foreignCode: foreignCodeFragment,
|
|
21
|
+
range: { start, end },
|
|
22
|
+
virtualShift: null
|
|
23
|
+
});
|
|
24
|
+
return extracts;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=text_extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text_extractor.js","sourceRoot":"","sources":["../../src/extractors/text_extractor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,OAAO,wBAAwB;IAMnC,YAAY,OAA0C;QACpD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,cAAc,CAAC,IAAY,EAAE,QAAkB;QAC7C,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,kBAAkB,CAAC,IAAY;QAC7B,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE7B,IAAI,QAAQ,GAAG,IAAI,KAAK,EAAkB,CAAC;QAE3C,IAAI,mBAAmB,GAAG,IAAI,CAAC;QAE/B,IAAI,KAAK,GAAG,gBAAgB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACvC,IAAI,GAAG,GAAG,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAE9D,QAAQ,CAAC,IAAI,CAAC;YACZ,QAAQ,EAAE,EAAE;YACZ,WAAW,EAAE,mBAAmB;YAChC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE;YACrB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
2
|
+
import { CellType } from '@jupyterlab/nbformat';
|
|
3
|
+
import { LanguageIdentifier } from '../lsp';
|
|
4
|
+
export interface IExtractedCode {
|
|
5
|
+
/**
|
|
6
|
+
* Foreign code (may be empty, for example line of '%R') or null if none.
|
|
7
|
+
*/
|
|
8
|
+
foreignCode: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Range of the foreign code relative to the original source.
|
|
11
|
+
* `null` is used internally to represent a leftover host code after extraction.
|
|
12
|
+
*/
|
|
13
|
+
range: CodeEditor.IRange | null;
|
|
14
|
+
/**
|
|
15
|
+
* Shift due to any additional code inserted at the beginning of the virtual document
|
|
16
|
+
* (usually in order to mock the arguments passed to a magic, or to provide other context clues for the linters)
|
|
17
|
+
*/
|
|
18
|
+
virtualShift: CodeEditor.IPosition | null;
|
|
19
|
+
/**
|
|
20
|
+
* Code to be retained in the virtual document of the host.
|
|
21
|
+
*/
|
|
22
|
+
hostCode: string | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Foreign code extractor makes it possible to analyze code of language X embedded in code (or notebook) of language Y.
|
|
26
|
+
*
|
|
27
|
+
* The typical examples are:
|
|
28
|
+
* - (X=CSS< Y=HTML), or
|
|
29
|
+
* - (X=JavaScript, Y=HTML),
|
|
30
|
+
*
|
|
31
|
+
* while in the data analysis realm, examples include:
|
|
32
|
+
* - (X=R, Y=IPython),
|
|
33
|
+
* - (X=LATEX Y=IPython),
|
|
34
|
+
* - (X=SQL, Y=IPython)
|
|
35
|
+
*
|
|
36
|
+
* This extension does not aim to provide comprehensive abilities for foreign code extraction,
|
|
37
|
+
* but it does intend to provide stable interface for other extensions to build on it.
|
|
38
|
+
*
|
|
39
|
+
* A simple, regular expression based, configurable foreign extractor is implemented
|
|
40
|
+
* to provide a good reference and a good initial experience for the users.
|
|
41
|
+
*/
|
|
42
|
+
export interface IForeignCodeExtractor {
|
|
43
|
+
/**
|
|
44
|
+
* The foreign language.
|
|
45
|
+
*/
|
|
46
|
+
language: LanguageIdentifier;
|
|
47
|
+
cellType: CellType[];
|
|
48
|
+
/**
|
|
49
|
+
* Split the code into the host and foreign code (if any foreign code was detected)
|
|
50
|
+
*/
|
|
51
|
+
extractForeignCode(code: string): IExtractedCode[];
|
|
52
|
+
/**
|
|
53
|
+
* Does the extractor produce code which should be appended to the previously established virtual document (False)
|
|
54
|
+
* of the same language, or does it produce standalone snippets which require separate connections (True)?
|
|
55
|
+
*/
|
|
56
|
+
standalone: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Test if there is any foreign code in provided code snippet.
|
|
59
|
+
*/
|
|
60
|
+
hasForeignCode(code: string, cellType: CellType): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Extension of the virtual document (some servers check extensions of files), e.g. 'py' or 'R'.
|
|
63
|
+
*/
|
|
64
|
+
fileExtension: string;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/extractors/types.ts"],"names":[],"mappings":""}
|
package/lib/feature.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ISignal } from '@lumino/signaling';
|
|
2
|
+
import { ClientCapabilities } from './lsp';
|
|
3
|
+
import { IFeature, ILSPFeatureManager } from './tokens';
|
|
4
|
+
export declare class FeatureManager implements ILSPFeatureManager {
|
|
5
|
+
readonly features: Array<IFeature>;
|
|
6
|
+
private _featuresRegistered;
|
|
7
|
+
constructor();
|
|
8
|
+
register(feature: IFeature): void;
|
|
9
|
+
get featuresRegistered(): ISignal<ILSPFeatureManager, IFeature>;
|
|
10
|
+
clientCapabilities(): ClientCapabilities;
|
|
11
|
+
}
|
package/lib/feature.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Signal } from '@lumino/signaling';
|
|
2
|
+
import mergeWith from 'lodash.mergewith';
|
|
3
|
+
export class FeatureManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.features = [];
|
|
6
|
+
this._featuresRegistered = new Signal(this);
|
|
7
|
+
}
|
|
8
|
+
register(feature) {
|
|
9
|
+
if (this.features.some(ft => ft.id === feature.id)) {
|
|
10
|
+
console.warn(`Feature with id ${feature.id} is already registered, skipping.`);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.features.push(feature);
|
|
14
|
+
this._featuresRegistered.emit(feature);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
get featuresRegistered() {
|
|
18
|
+
return this._featuresRegistered;
|
|
19
|
+
}
|
|
20
|
+
clientCapabilities() {
|
|
21
|
+
let capabilities = {};
|
|
22
|
+
for (const feature of this.features) {
|
|
23
|
+
if (!feature.capabilities) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
capabilities = mergeWith(capabilities, feature.capabilities);
|
|
27
|
+
}
|
|
28
|
+
return capabilities;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAKzC,MAAM,OAAO,cAAc;IAGzB;QAFgB,aAAQ,GAAoB,EAAE,CAAC;QAG7C,IAAI,CAAC,mBAAmB,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ,CAAC,OAAiB;QACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,EAAE,CAAC,EAAE;YAClD,OAAO,CAAC,IAAI,CACV,mBAAmB,OAAO,CAAC,EAAE,mCAAmC,CACjE,CAAC;SACH;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxC;IACH,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,kBAAkB;QAChB,IAAI,YAAY,GAAuB,EAAE,CAAC;QAC1C,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE;YACnC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;gBACzB,SAAS;aACV;YACD,YAAY,GAAG,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;SAC9D;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module lsp
|
|
4
|
+
*/
|
|
5
|
+
export * from './connection_manager';
|
|
6
|
+
export * from './manager';
|
|
7
|
+
export * from './tokens';
|
|
8
|
+
export * from './adapters/adapter';
|
|
9
|
+
export * from './positioning';
|
|
10
|
+
export * from './virtual/document';
|
|
11
|
+
export * from './utils';
|
|
12
|
+
export * from './connection';
|
|
13
|
+
export * from './feature';
|
|
14
|
+
export * from './extractors/manager';
|
|
15
|
+
export * from './extractors/text_extractor';
|
|
16
|
+
export * from './extractors/types';
|
|
17
|
+
export * from './plugin';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module lsp
|
|
8
|
+
*/
|
|
9
|
+
export * from './connection_manager';
|
|
10
|
+
export * from './manager';
|
|
11
|
+
export * from './tokens';
|
|
12
|
+
export * from './adapters/adapter';
|
|
13
|
+
export * from './positioning';
|
|
14
|
+
export * from './virtual/document';
|
|
15
|
+
export * from './utils';
|
|
16
|
+
export * from './connection';
|
|
17
|
+
export * from './feature';
|
|
18
|
+
export * from './extractors/manager';
|
|
19
|
+
export * from './extractors/text_extractor';
|
|
20
|
+
export * from './extractors/types';
|
|
21
|
+
export * from './plugin';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;+EAG+E;AAC/E;;;GAGG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC"}
|