@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,125 @@
|
|
|
1
|
+
import { JupyterFrontEnd } from '@jupyterlab/application';
|
|
2
|
+
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
3
|
+
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
|
|
4
|
+
import * as nbformat from '@jupyterlab/nbformat';
|
|
5
|
+
import { ITranslator, TranslationBundle } from '@jupyterlab/translation';
|
|
6
|
+
import { Signal } from '@lumino/signaling';
|
|
7
|
+
import { LanguageIdentifier } from '../lsp';
|
|
8
|
+
import { IVirtualPosition } from '../positioning';
|
|
9
|
+
import { IDocumentConnectionData, ILSPCodeExtractorsManager, ILSPDocumentConnectionManager, ILSPFeatureManager } from '../tokens';
|
|
10
|
+
import { IForeignContext, VirtualDocument } from '../virtual/document';
|
|
11
|
+
export declare class StatusMessage {
|
|
12
|
+
/**
|
|
13
|
+
* The text message to be shown on the statusbar
|
|
14
|
+
*/
|
|
15
|
+
message: string;
|
|
16
|
+
changed: Signal<StatusMessage, void>;
|
|
17
|
+
private timer;
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Set the text message and (optionally) the timeout to remove it.
|
|
21
|
+
* @param message
|
|
22
|
+
* @param timeout - number of ms to until the message is cleaned;
|
|
23
|
+
* -1 if the message should stay up indefinitely;
|
|
24
|
+
* defaults to 3000ms (3 seconds)
|
|
25
|
+
*/
|
|
26
|
+
set(message: string, timeout?: number): void;
|
|
27
|
+
clear(): void;
|
|
28
|
+
private expireTimer;
|
|
29
|
+
}
|
|
30
|
+
export interface IEditorChangedData {
|
|
31
|
+
editor: CodeEditor.IEditor;
|
|
32
|
+
}
|
|
33
|
+
export interface IAdapterOptions {
|
|
34
|
+
app: JupyterFrontEnd;
|
|
35
|
+
connectionManager: ILSPDocumentConnectionManager;
|
|
36
|
+
featureManager: ILSPFeatureManager;
|
|
37
|
+
foreignCodeExtractorsManager: ILSPCodeExtractorsManager;
|
|
38
|
+
translator?: ITranslator;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Foreign code: low level adapter is not aware of the presence of foreign languages;
|
|
42
|
+
* it operates on the virtual document and must not attempt to infer the language dependencies
|
|
43
|
+
* as this would make the logic of inspections caching impossible to maintain, thus the WidgetAdapter
|
|
44
|
+
* has to handle that, keeping multiple connections and multiple virtual documents.
|
|
45
|
+
*/
|
|
46
|
+
export declare abstract class WidgetAdapter<T extends IDocumentWidget> {
|
|
47
|
+
protected options: IAdapterOptions;
|
|
48
|
+
widget: T;
|
|
49
|
+
adapterConnected: Signal<WidgetAdapter<T>, IDocumentConnectionData>;
|
|
50
|
+
isConnected: boolean;
|
|
51
|
+
connectionManager: ILSPDocumentConnectionManager;
|
|
52
|
+
trans: TranslationBundle;
|
|
53
|
+
protected isDisposed: boolean;
|
|
54
|
+
protected app: JupyterFrontEnd;
|
|
55
|
+
activeEditorChanged: Signal<WidgetAdapter<T>, IEditorChangedData>;
|
|
56
|
+
editorAdded: Signal<WidgetAdapter<T>, IEditorChangedData>;
|
|
57
|
+
editorRemoved: Signal<WidgetAdapter<T>, IEditorChangedData>;
|
|
58
|
+
updateFinished: Promise<void>;
|
|
59
|
+
initialized: Promise<void>;
|
|
60
|
+
virtualDocument: VirtualDocument;
|
|
61
|
+
/**
|
|
62
|
+
* (re)create virtual document using current path and language
|
|
63
|
+
*/
|
|
64
|
+
abstract createVirtualDocument(): VirtualDocument;
|
|
65
|
+
abstract getEditorIndexAt(position: IVirtualPosition): number;
|
|
66
|
+
abstract getEditorIndex(ceEditor: CodeEditor.IEditor): number;
|
|
67
|
+
abstract getEditorWrapper(ceEditor: CodeEditor.IEditor): HTMLElement;
|
|
68
|
+
protected constructor(options: IAdapterOptions, widget: T);
|
|
69
|
+
onConnectionClosed(_: ILSPDocumentConnectionManager, { virtualDocument }: IDocumentConnectionData): void;
|
|
70
|
+
dispose(): void;
|
|
71
|
+
abstract get documentPath(): string;
|
|
72
|
+
abstract get mimeType(): string;
|
|
73
|
+
get widgetId(): string;
|
|
74
|
+
get language(): LanguageIdentifier;
|
|
75
|
+
abstract get languageFileExtension(): string | undefined;
|
|
76
|
+
disconnect(): void;
|
|
77
|
+
protected reloadConnection(): void;
|
|
78
|
+
protected onSaveState(context: DocumentRegistry.IContext<DocumentRegistry.IModel>, state: DocumentRegistry.SaveState): void;
|
|
79
|
+
abstract activeEditor: CodeEditor.IEditor | undefined;
|
|
80
|
+
abstract get editors(): {
|
|
81
|
+
ceEditor: CodeEditor.IEditor;
|
|
82
|
+
type: nbformat.CellType;
|
|
83
|
+
}[];
|
|
84
|
+
/**
|
|
85
|
+
* public for use in tests (but otherwise could be private)
|
|
86
|
+
*/
|
|
87
|
+
updateDocuments(): Promise<void> | undefined;
|
|
88
|
+
get hasMultipleEditors(): boolean;
|
|
89
|
+
protected onConnected(data: IDocumentConnectionData): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Opens a connection for the document. The connection may or may
|
|
92
|
+
* not be initialized, yet, and depending on when this is called, the client
|
|
93
|
+
* may not be fully connected.
|
|
94
|
+
*
|
|
95
|
+
* @param virtualDocument a VirtualDocument
|
|
96
|
+
* @param sendOpen whether to open the document immediately
|
|
97
|
+
*/
|
|
98
|
+
protected connectDocument(virtualDocument: VirtualDocument, sendOpen?: boolean): Promise<void>;
|
|
99
|
+
protected initVirtual(): void;
|
|
100
|
+
private onForeignDocumentClosed;
|
|
101
|
+
/**
|
|
102
|
+
* Handler for opening a document contained in a parent document. The assumption
|
|
103
|
+
* is that the editor already exists for this, and as such the document
|
|
104
|
+
* should be queued for immediate opening.
|
|
105
|
+
*
|
|
106
|
+
* @param host the VirtualDocument that contains the VirtualDocument in another language
|
|
107
|
+
* @param context information about the foreign VirtualDocument
|
|
108
|
+
*/
|
|
109
|
+
protected onForeignDocumentOpened(_: VirtualDocument, context: IForeignContext): Promise<void>;
|
|
110
|
+
documentChanged(virtualDocument: VirtualDocument, document: VirtualDocument, isInit?: boolean): void;
|
|
111
|
+
private connect;
|
|
112
|
+
/**
|
|
113
|
+
* Connect the change signal in order to update all virtual documents after a change.
|
|
114
|
+
*
|
|
115
|
+
* Update to the state of a notebook may be done without a notice on the CodeMirror level,
|
|
116
|
+
* e.g. when a cell is deleted. Therefore a JupyterLab-specific signals are watched instead.
|
|
117
|
+
*
|
|
118
|
+
* While by not using the change event of CodeMirror editors we loose an easy way to send selective,
|
|
119
|
+
* (range) updates this can be still implemented by comparison of before/after states of the
|
|
120
|
+
* virtual documents, which is even more resilient and -obviously - editor-independent.
|
|
121
|
+
*/
|
|
122
|
+
private connectContentChangedSignal;
|
|
123
|
+
private onContentChanged;
|
|
124
|
+
abstract get wrapperElement(): HTMLElement;
|
|
125
|
+
}
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { Dialog, showDialog } from '@jupyterlab/apputils';
|
|
2
|
+
import { nullTranslator } from '@jupyterlab/translation';
|
|
3
|
+
import { Signal } from '@lumino/signaling';
|
|
4
|
+
import mergeWith from 'lodash.mergewith';
|
|
5
|
+
const createButton = Dialog.createButton;
|
|
6
|
+
export class StatusMessage {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.message = '';
|
|
9
|
+
this.changed = new Signal(this);
|
|
10
|
+
this.timer = null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Set the text message and (optionally) the timeout to remove it.
|
|
14
|
+
* @param message
|
|
15
|
+
* @param timeout - number of ms to until the message is cleaned;
|
|
16
|
+
* -1 if the message should stay up indefinitely;
|
|
17
|
+
* defaults to 3000ms (3 seconds)
|
|
18
|
+
*/
|
|
19
|
+
set(message, timeout = 1000 * 3) {
|
|
20
|
+
this.expireTimer();
|
|
21
|
+
this.message = message;
|
|
22
|
+
this.changed.emit();
|
|
23
|
+
if (timeout !== -1) {
|
|
24
|
+
this.timer = window.setTimeout(this.clear.bind(this), timeout);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
clear() {
|
|
28
|
+
this.message = '';
|
|
29
|
+
this.changed.emit();
|
|
30
|
+
}
|
|
31
|
+
expireTimer() {
|
|
32
|
+
if (this.timer !== null) {
|
|
33
|
+
window.clearTimeout(this.timer);
|
|
34
|
+
this.timer = 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The values should follow the https://microsoft.github.io/language-server-protocol/specification guidelines
|
|
40
|
+
*/
|
|
41
|
+
const MIME_TYPE_LANGUAGE_MAP = {
|
|
42
|
+
'text/x-rsrc': 'r',
|
|
43
|
+
'text/x-r-source': 'r',
|
|
44
|
+
// currently there are no LSP servers for IPython we are aware of
|
|
45
|
+
'text/x-ipython': 'python'
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Foreign code: low level adapter is not aware of the presence of foreign languages;
|
|
49
|
+
* it operates on the virtual document and must not attempt to infer the language dependencies
|
|
50
|
+
* as this would make the logic of inspections caching impossible to maintain, thus the WidgetAdapter
|
|
51
|
+
* has to handle that, keeping multiple connections and multiple virtual documents.
|
|
52
|
+
*/
|
|
53
|
+
export class WidgetAdapter {
|
|
54
|
+
// note: it could be using namespace/IOptions pattern,
|
|
55
|
+
// but I do not know how to make it work with the generic type T
|
|
56
|
+
// (other than using 'any' in the IOptions interface)
|
|
57
|
+
constructor(options, widget) {
|
|
58
|
+
this.options = options;
|
|
59
|
+
this.widget = widget;
|
|
60
|
+
this.isDisposed = false;
|
|
61
|
+
this.app = options.app;
|
|
62
|
+
this.connectionManager = options.connectionManager;
|
|
63
|
+
this.adapterConnected = new Signal(this);
|
|
64
|
+
this.activeEditorChanged = new Signal(this);
|
|
65
|
+
this.editorRemoved = new Signal(this);
|
|
66
|
+
this.editorAdded = new Signal(this);
|
|
67
|
+
this.isConnected = false;
|
|
68
|
+
this.trans = (options.translator || nullTranslator).load('jupyterlab-lsp');
|
|
69
|
+
// set up signal connections
|
|
70
|
+
this.widget.context.saveState.connect(this.onSaveState, this);
|
|
71
|
+
this.connectionManager.closed.connect(this.onConnectionClosed, this);
|
|
72
|
+
this.widget.disposed.connect(this.dispose, this);
|
|
73
|
+
}
|
|
74
|
+
onConnectionClosed(_, { virtualDocument }) {
|
|
75
|
+
if (virtualDocument === this.virtualDocument) {
|
|
76
|
+
this.dispose();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
dispose() {
|
|
80
|
+
if (this.isDisposed) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.widget.context.saveState.disconnect(this.onSaveState, this);
|
|
84
|
+
this.connectionManager.closed.disconnect(this.onConnectionClosed, this);
|
|
85
|
+
this.widget.disposed.disconnect(this.dispose, this);
|
|
86
|
+
this.disconnect();
|
|
87
|
+
// just to be sure
|
|
88
|
+
this.app = null;
|
|
89
|
+
this.widget = null;
|
|
90
|
+
this.connectionManager = null;
|
|
91
|
+
this.widget = null;
|
|
92
|
+
this.isDisposed = true;
|
|
93
|
+
}
|
|
94
|
+
get widgetId() {
|
|
95
|
+
return this.widget.id;
|
|
96
|
+
}
|
|
97
|
+
get language() {
|
|
98
|
+
// the values should follow https://microsoft.github.io/language-server-protocol/specification guidelines,
|
|
99
|
+
// see the table in https://microsoft.github.io/language-server-protocol/specification#textDocumentItem
|
|
100
|
+
if (MIME_TYPE_LANGUAGE_MAP.hasOwnProperty(this.mimeType)) {
|
|
101
|
+
return MIME_TYPE_LANGUAGE_MAP[this.mimeType];
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
let withoutParameters = this.mimeType.split(';')[0];
|
|
105
|
+
let [type, subtype] = withoutParameters.split('/');
|
|
106
|
+
if (type === 'application' || type === 'text') {
|
|
107
|
+
if (subtype.startsWith('x-')) {
|
|
108
|
+
return subtype.substr(2);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return subtype;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return this.mimeType;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
disconnect() {
|
|
120
|
+
this.connectionManager.unregisterDocument(this.virtualDocument);
|
|
121
|
+
this.widget.context.model.contentChanged.disconnect(this.onContentChanged, this);
|
|
122
|
+
// pretend that all editors were removed to trigger the disconnection of even handlers
|
|
123
|
+
// they will be connected again on new connection
|
|
124
|
+
for (let { ceEditor: editor } of this.editors) {
|
|
125
|
+
this.editorRemoved.emit({
|
|
126
|
+
editor: editor
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
this.virtualDocument.dispose();
|
|
130
|
+
}
|
|
131
|
+
// equivalent to triggering didClose and didOpen, as per syncing specification,
|
|
132
|
+
// but also reloads the connection; used during file rename (or when it was moved)
|
|
133
|
+
reloadConnection() {
|
|
134
|
+
// ignore premature calls (before the editor was initialized)
|
|
135
|
+
if (this.virtualDocument == null) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// disconnect all existing connections (and dispose adapters)
|
|
139
|
+
this.disconnect();
|
|
140
|
+
// recreate virtual document using current path and language
|
|
141
|
+
// as virtual editor assumes it gets the virtual document at init,
|
|
142
|
+
// just dispose virtual editor (which disposes virtual document too)
|
|
143
|
+
// and re-initialize both virtual editor and document
|
|
144
|
+
this.initVirtual();
|
|
145
|
+
// reconnect
|
|
146
|
+
this.connectDocument(this.virtualDocument, true).catch(console.warn);
|
|
147
|
+
}
|
|
148
|
+
onSaveState(context, state) {
|
|
149
|
+
// ignore premature calls (before the editor was initialized)
|
|
150
|
+
if (this.virtualDocument == null) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// TODO: remove workaround no later than with 3.2 release of JupyterLab
|
|
154
|
+
// workaround for https://github.com/jupyterlab/jupyterlab/issues/10721
|
|
155
|
+
// while already reverted in https://github.com/jupyterlab/jupyterlab/pull/10741,
|
|
156
|
+
// it was not released yet and many users will continue to run 3.1.0 and 3.1.1
|
|
157
|
+
// so lets workaround it for now
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
const completedManually = state === 'completed manually';
|
|
161
|
+
if (state === 'completed' || completedManually) {
|
|
162
|
+
// note: must only be send to the appropriate connections as
|
|
163
|
+
// some servers (Julia) break if they receive save notification
|
|
164
|
+
// for a document that was not opened before, see:
|
|
165
|
+
// https://github.com/jupyter-lsp/jupyterlab-lsp/issues/490
|
|
166
|
+
const documentsToSave = [this.virtualDocument];
|
|
167
|
+
for (let virtualDocument of documentsToSave) {
|
|
168
|
+
let connection = this.connectionManager.connections.get(virtualDocument.uri);
|
|
169
|
+
if (!connection) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
connection.sendSaved(virtualDocument.documentInfo);
|
|
173
|
+
for (let foreign of virtualDocument.foreignDocuments.values()) {
|
|
174
|
+
documentsToSave.push(foreign);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* public for use in tests (but otherwise could be private)
|
|
181
|
+
*/
|
|
182
|
+
updateDocuments() {
|
|
183
|
+
if (this.isDisposed) {
|
|
184
|
+
console.warn('Cannot update documents: adapter disposed');
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
return this.virtualDocument.updateManager.updateDocuments(this.editors.map(({ ceEditor, type }) => {
|
|
188
|
+
return {
|
|
189
|
+
ceEditor: ceEditor,
|
|
190
|
+
value: ceEditor.model.value.text,
|
|
191
|
+
type
|
|
192
|
+
};
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
get hasMultipleEditors() {
|
|
196
|
+
return this.editors.length > 1;
|
|
197
|
+
}
|
|
198
|
+
async onConnected(data) {
|
|
199
|
+
let { virtualDocument } = data;
|
|
200
|
+
this.adapterConnected.emit(data);
|
|
201
|
+
this.isConnected = true;
|
|
202
|
+
const promise = this.updateDocuments();
|
|
203
|
+
if (!promise) {
|
|
204
|
+
console.warn('Could not update documents');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
await promise.then(() => {
|
|
208
|
+
// refresh the document on the LSP server
|
|
209
|
+
this.documentChanged(virtualDocument, virtualDocument, true);
|
|
210
|
+
});
|
|
211
|
+
// Note: the logger extension behaves badly with non-default names
|
|
212
|
+
// as it changes the source to the active file afterwards anyways
|
|
213
|
+
// const loggerSourceName = virtualDocument.uri;
|
|
214
|
+
let log;
|
|
215
|
+
log = (text) => console.log(text);
|
|
216
|
+
data.connection.serverNotifications['$/logTrace'].connect((connection, message) => {
|
|
217
|
+
console.log(data.connection.serverIdentifier, 'trace', virtualDocument.uri, message);
|
|
218
|
+
});
|
|
219
|
+
data.connection.serverNotifications['window/logMessage'].connect((connection, message) => {
|
|
220
|
+
log(connection.serverIdentifier + ': ' + message.message);
|
|
221
|
+
});
|
|
222
|
+
data.connection.serverNotifications['window/showMessage'].connect((connection, message) => {
|
|
223
|
+
void showDialog({
|
|
224
|
+
title: this.trans.__('Message from ') + connection.serverIdentifier,
|
|
225
|
+
body: message.message
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
data.connection.serverRequests['window/showMessageRequest'].setHandler(async (params) => {
|
|
229
|
+
const actionItems = params.actions;
|
|
230
|
+
const buttons = actionItems
|
|
231
|
+
? actionItems.map(action => {
|
|
232
|
+
return createButton({
|
|
233
|
+
label: action.title
|
|
234
|
+
});
|
|
235
|
+
})
|
|
236
|
+
: [createButton({ label: this.trans.__('Dismiss') })];
|
|
237
|
+
const result = await showDialog({
|
|
238
|
+
title: this.trans.__('Message from ') + data.connection.serverIdentifier,
|
|
239
|
+
body: params.message,
|
|
240
|
+
buttons: buttons
|
|
241
|
+
});
|
|
242
|
+
const choice = buttons.indexOf(result.button);
|
|
243
|
+
if (choice === -1) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
if (actionItems) {
|
|
247
|
+
return actionItems[choice];
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Opens a connection for the document. The connection may or may
|
|
254
|
+
* not be initialized, yet, and depending on when this is called, the client
|
|
255
|
+
* may not be fully connected.
|
|
256
|
+
*
|
|
257
|
+
* @param virtualDocument a VirtualDocument
|
|
258
|
+
* @param sendOpen whether to open the document immediately
|
|
259
|
+
*/
|
|
260
|
+
async connectDocument(virtualDocument, sendOpen = false) {
|
|
261
|
+
virtualDocument.foreignDocumentOpened.connect(this.onForeignDocumentOpened, this);
|
|
262
|
+
const connectionContext = await this.connect(virtualDocument).catch(console.error);
|
|
263
|
+
if (connectionContext && connectionContext.connection) {
|
|
264
|
+
virtualDocument.changed.connect(this.documentChanged, this);
|
|
265
|
+
if (sendOpen) {
|
|
266
|
+
connectionContext.connection.sendOpenWhenReady(virtualDocument.documentInfo);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
initVirtual() {
|
|
271
|
+
let virtualDocument = this.createVirtualDocument();
|
|
272
|
+
if (virtualDocument == null) {
|
|
273
|
+
console.error('Could not initialize a VirtualDocument for adapter: ', this);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.virtualDocument = virtualDocument;
|
|
277
|
+
this.connectContentChangedSignal();
|
|
278
|
+
}
|
|
279
|
+
onForeignDocumentClosed(_, context) {
|
|
280
|
+
const { foreignDocument } = context;
|
|
281
|
+
foreignDocument.foreignDocumentClosed.disconnect(this.onForeignDocumentClosed, this);
|
|
282
|
+
foreignDocument.foreignDocumentOpened.disconnect(this.onForeignDocumentOpened, this);
|
|
283
|
+
foreignDocument.changed.disconnect(this.documentChanged, this);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Handler for opening a document contained in a parent document. The assumption
|
|
287
|
+
* is that the editor already exists for this, and as such the document
|
|
288
|
+
* should be queued for immediate opening.
|
|
289
|
+
*
|
|
290
|
+
* @param host the VirtualDocument that contains the VirtualDocument in another language
|
|
291
|
+
* @param context information about the foreign VirtualDocument
|
|
292
|
+
*/
|
|
293
|
+
async onForeignDocumentOpened(_, context) {
|
|
294
|
+
const { foreignDocument } = context;
|
|
295
|
+
await this.connectDocument(foreignDocument, true);
|
|
296
|
+
foreignDocument.foreignDocumentClosed.connect(this.onForeignDocumentClosed, this);
|
|
297
|
+
}
|
|
298
|
+
documentChanged(virtualDocument, document, isInit = false) {
|
|
299
|
+
if (this.isDisposed) {
|
|
300
|
+
console.warn('Cannot swap document: adapter disposed');
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// TODO only send the difference, using connection.sendSelectiveChange()
|
|
304
|
+
let connection = this.connectionManager.connections.get(virtualDocument.uri);
|
|
305
|
+
if (!(connection === null || connection === void 0 ? void 0 : connection.isReady)) {
|
|
306
|
+
console.log('Skipping document update signal: connection not ready');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
connection.sendFullTextChange(virtualDocument.value, virtualDocument.documentInfo);
|
|
310
|
+
// the first change (initial) is not propagated to features,
|
|
311
|
+
// as it has no associated CodeMirrorChange object
|
|
312
|
+
if (!isInit) {
|
|
313
|
+
// TODO??
|
|
314
|
+
// guarantee that the virtual editor won't perform an update of the virtual documents while
|
|
315
|
+
// the changes are recorded...
|
|
316
|
+
// TODO this is not ideal - why it solves the problem of some errors,
|
|
317
|
+
// it introduces an unnecessary delay. A better way could be to invalidate some of the updates when a new one comes in.
|
|
318
|
+
// but maybe not every one (then the outdated state could be kept for too long fo a user who writes very quickly)
|
|
319
|
+
// also we would not want to invalidate the updates for the purpose of autocompletion (the trigger characters)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async connect(virtualDocument) {
|
|
323
|
+
let language = virtualDocument.language;
|
|
324
|
+
let capabilities = {
|
|
325
|
+
textDocument: {
|
|
326
|
+
synchronization: {
|
|
327
|
+
dynamicRegistration: true,
|
|
328
|
+
willSave: false,
|
|
329
|
+
didSave: true,
|
|
330
|
+
willSaveWaitUntil: false
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
workspace: {
|
|
334
|
+
didChangeConfiguration: {
|
|
335
|
+
dynamicRegistration: true
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
capabilities = mergeWith(capabilities, this.options.featureManager.clientCapabilities());
|
|
340
|
+
let options = {
|
|
341
|
+
capabilities,
|
|
342
|
+
virtualDocument,
|
|
343
|
+
language,
|
|
344
|
+
hasLspSupportedFile: virtualDocument.hasLspSupportedFile
|
|
345
|
+
};
|
|
346
|
+
let connection = await this.connectionManager.connect(options);
|
|
347
|
+
if (connection) {
|
|
348
|
+
await this.onConnected({ virtualDocument, connection });
|
|
349
|
+
return {
|
|
350
|
+
connection,
|
|
351
|
+
virtualDocument
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Connect the change signal in order to update all virtual documents after a change.
|
|
360
|
+
*
|
|
361
|
+
* Update to the state of a notebook may be done without a notice on the CodeMirror level,
|
|
362
|
+
* e.g. when a cell is deleted. Therefore a JupyterLab-specific signals are watched instead.
|
|
363
|
+
*
|
|
364
|
+
* While by not using the change event of CodeMirror editors we loose an easy way to send selective,
|
|
365
|
+
* (range) updates this can be still implemented by comparison of before/after states of the
|
|
366
|
+
* virtual documents, which is even more resilient and -obviously - editor-independent.
|
|
367
|
+
*/
|
|
368
|
+
connectContentChangedSignal() {
|
|
369
|
+
this.widget.context.model.contentChanged.connect(this.onContentChanged, this);
|
|
370
|
+
}
|
|
371
|
+
async onContentChanged(_slot) {
|
|
372
|
+
// update the virtual documents (sending the updates to LSP is out of scope here)
|
|
373
|
+
const promise = this.updateDocuments();
|
|
374
|
+
if (!promise) {
|
|
375
|
+
console.warn('Could not update documents');
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
this.updateFinished = promise.catch(console.warn);
|
|
379
|
+
await this.updateFinished;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
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Position, LspWsConnection } from 'lsp-ws-connection';
|
|
2
|
+
import { ClientNotifications, ClientRequests, ILSPConnection, ILSPOptions, Method, ServerNotifications, ServerRequests } from './tokens';
|
|
3
|
+
import type * as lsp from 'vscode-languageserver-protocol';
|
|
4
|
+
export declare const Provider: {
|
|
5
|
+
[key: string]: keyof lsp.ServerCapabilities;
|
|
6
|
+
};
|
|
7
|
+
declare type AnyMethod = Method.ServerNotification | Method.ClientNotification | Method.ClientRequest | Method.ServerRequest;
|
|
8
|
+
declare enum MessageKind {
|
|
9
|
+
clientNotifiedServer = 0,
|
|
10
|
+
serverNotifiedClient = 1,
|
|
11
|
+
serverRequested = 2,
|
|
12
|
+
clientRequested = 3,
|
|
13
|
+
resultForClient = 4,
|
|
14
|
+
responseForServer = 5
|
|
15
|
+
}
|
|
16
|
+
interface IMessageLog<T extends AnyMethod = AnyMethod> {
|
|
17
|
+
method: T;
|
|
18
|
+
message: any;
|
|
19
|
+
}
|
|
20
|
+
export declare class LSPConnection extends LspWsConnection implements ILSPConnection {
|
|
21
|
+
serverIdentifier?: string;
|
|
22
|
+
serverLanguage?: string;
|
|
23
|
+
clientNotifications: ClientNotifications;
|
|
24
|
+
serverNotifications: ServerNotifications;
|
|
25
|
+
clientRequests: ClientRequests;
|
|
26
|
+
serverRequests: ServerRequests;
|
|
27
|
+
logAllCommunication: boolean;
|
|
28
|
+
protected documentsToOpen: IDocumentInfo[];
|
|
29
|
+
private _options;
|
|
30
|
+
constructor(options: ILSPOptions);
|
|
31
|
+
log(kind: MessageKind, message: IMessageLog): void;
|
|
32
|
+
protected constructNotificationHandlers<T extends ServerNotifications | ClientNotifications>(methods: typeof Method.ServerNotification | typeof Method.ClientNotification): T;
|
|
33
|
+
protected constructClientRequestHandler<T extends ClientRequests, U extends keyof T = keyof T>(methods: typeof Method.ClientRequest): T;
|
|
34
|
+
protected constructServerRequestHandler<T extends ServerRequests, U extends keyof T = keyof T>(methods: typeof Method.ServerRequest): T;
|
|
35
|
+
/**
|
|
36
|
+
* Initialization parameters to be sent to the language server.
|
|
37
|
+
* Subclasses can overload this when adding more features.
|
|
38
|
+
*/
|
|
39
|
+
protected initializeParams(): lsp.InitializeParams;
|
|
40
|
+
sendOpenWhenReady(documentInfo: IDocumentInfo): void;
|
|
41
|
+
protected onServerInitialized(params: lsp.InitializeResult): void;
|
|
42
|
+
protected afterInitialized(): void;
|
|
43
|
+
sendSelectiveChange(changeEvent: lsp.TextDocumentContentChangeEvent, documentInfo: IDocumentInfo): void;
|
|
44
|
+
sendFullTextChange(text: string, documentInfo: IDocumentInfo): void;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated The method should not be used in new code. Use provides() instead.
|
|
47
|
+
*/
|
|
48
|
+
isRenameSupported(): boolean;
|
|
49
|
+
provides(provider: keyof lsp.ServerCapabilities): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated The method should not be used in new code
|
|
52
|
+
*/
|
|
53
|
+
rename(location: IPosition, documentInfo: IDocumentInfo, newName: string, emit?: boolean): Promise<lsp.WorkspaceEdit | null>;
|
|
54
|
+
connect(socket: WebSocket): this;
|
|
55
|
+
private closingManually;
|
|
56
|
+
close(): void;
|
|
57
|
+
private _sendChange;
|
|
58
|
+
getCompletionResolve(completionItem: lsp.CompletionItem): Promise<lsp.CompletionItem | undefined>;
|
|
59
|
+
/**
|
|
60
|
+
* Does support completionItem/resolve?
|
|
61
|
+
* @deprecated The method should not be used in new code
|
|
62
|
+
*/
|
|
63
|
+
isCompletionResolveProvider(): boolean;
|
|
64
|
+
}
|
|
65
|
+
export {};
|