codemirror-languageserver 1.17.1 → 1.18.1
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/dist/changes.d.ts +3 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +46 -18
- package/dist/plugin.d.ts +10 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export { LanguageServerClient, languageServerPlugin } from './plugin';
|
|
1
|
+
export { LanguageServerClient, languageServerPlugin, SynchronizationMethod, } from './plugin';
|
|
2
2
|
export { jumpToDefinition, jumpToDefinitionPos, jumpToDefinitionKeymap, } from './definition';
|
|
3
3
|
export { PyrightInitializationOptions, RustAnalyzerInitializationOptions, TypeScriptInitializationOptions, ESLintInitializationOptions, ClangdInitializationOptions, GoplsInitializationOptions, } from './initialization';
|
|
4
|
-
import { LanguageServerClient } from './plugin';
|
|
4
|
+
import { LanguageServerClient, SynchronizationMethod } from './plugin';
|
|
5
5
|
import type { LanguageServerClientOptions, LanguageServerBaseOptions } from './plugin';
|
|
6
6
|
interface LanguageServerOptions<InitializationOptions = unknown> extends LanguageServerClientOptions<InitializationOptions> {
|
|
7
7
|
client?: LanguageServerClient<InitializationOptions>;
|
|
8
8
|
allowHTMLContent?: boolean;
|
|
9
|
+
synchronizationMethod?: SynchronizationMethod;
|
|
9
10
|
}
|
|
10
11
|
interface LanguageServerWebsocketOptions<InitializationOptions = unknown> extends LanguageServerBaseOptions {
|
|
11
12
|
serverUri: `ws://${string}` | `wss://${string}`;
|
package/dist/index.js
CHANGED
|
@@ -24,8 +24,28 @@ function offsetToPos(doc, offset) {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
function changeSetToEvents(doc, changes) {
|
|
28
|
+
const events = [];
|
|
29
|
+
changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
30
|
+
events.push({
|
|
31
|
+
range: {
|
|
32
|
+
start: offsetToPos(doc, fromA),
|
|
33
|
+
end: offsetToPos(doc, toA),
|
|
34
|
+
},
|
|
35
|
+
text: inserted.toString(),
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
events.sort((a, b) => {
|
|
39
|
+
if (!('range' in a))
|
|
40
|
+
return 1;
|
|
41
|
+
if (!('range' in b))
|
|
42
|
+
return -1;
|
|
43
|
+
return (posToOffset(doc, b.range.start) - posToOffset(doc, a.range.start));
|
|
44
|
+
});
|
|
45
|
+
return events;
|
|
46
|
+
}
|
|
47
|
+
|
|
27
48
|
const timeout = 10000;
|
|
28
|
-
const changesDelay = 500;
|
|
29
49
|
const CompletionItemKindMap = Object.fromEntries(Object.entries(CompletionItemKind).map(([key, value]) => [value, key]));
|
|
30
50
|
const useLast = (values) => values.reduce((_, v) => v, '');
|
|
31
51
|
Facet.define({
|
|
@@ -186,32 +206,42 @@ class LanguageServerClient {
|
|
|
186
206
|
}
|
|
187
207
|
}
|
|
188
208
|
}
|
|
209
|
+
var SynchronizationMethod;
|
|
210
|
+
(function (SynchronizationMethod) {
|
|
211
|
+
SynchronizationMethod["Full"] = "full";
|
|
212
|
+
SynchronizationMethod["Incremental"] = "incremental";
|
|
213
|
+
})(SynchronizationMethod || (SynchronizationMethod = {}));
|
|
189
214
|
class LanguageServerPlugin {
|
|
190
|
-
constructor(view, { client, documentUri, languageId, allowHTMLContent, }) {
|
|
215
|
+
constructor(view, { client, documentUri, languageId, allowHTMLContent, synchronizationMethod, }) {
|
|
191
216
|
this.view = view;
|
|
192
217
|
this.client = client;
|
|
193
218
|
this.documentUri = documentUri;
|
|
194
219
|
this.languageId = languageId;
|
|
195
220
|
this.allowHTMLContent = allowHTMLContent;
|
|
221
|
+
this.synchronizationMethod =
|
|
222
|
+
synchronizationMethod !== null && synchronizationMethod !== void 0 ? synchronizationMethod : SynchronizationMethod.Full;
|
|
196
223
|
this.documentVersion = 0;
|
|
197
|
-
this.changesTimeout = 0;
|
|
198
224
|
this.client.attachPlugin(this);
|
|
199
225
|
this.initialize({
|
|
200
226
|
documentText: this.view.state.doc.toString(),
|
|
201
227
|
});
|
|
202
228
|
}
|
|
203
|
-
update({ docChanged }) {
|
|
229
|
+
update({ state, changes, startState, docChanged }) {
|
|
204
230
|
if (!docChanged) {
|
|
205
231
|
return;
|
|
206
232
|
}
|
|
207
|
-
|
|
208
|
-
|
|
233
|
+
switch (this.synchronizationMethod) {
|
|
234
|
+
case SynchronizationMethod.Full:
|
|
235
|
+
this.sendChanges([
|
|
236
|
+
{
|
|
237
|
+
text: this.view.state.doc.toString(),
|
|
238
|
+
},
|
|
239
|
+
]);
|
|
240
|
+
break;
|
|
241
|
+
case SynchronizationMethod.Incremental:
|
|
242
|
+
this.sendChanges(changeSetToEvents(startState.doc, changes));
|
|
243
|
+
break;
|
|
209
244
|
}
|
|
210
|
-
this.changesTimeout = self.setTimeout(() => {
|
|
211
|
-
this.sendChange({
|
|
212
|
-
documentText: this.view.state.doc.toString(),
|
|
213
|
-
});
|
|
214
|
-
}, changesDelay);
|
|
215
245
|
}
|
|
216
246
|
destroy() {
|
|
217
247
|
this.client.detachPlugin(this);
|
|
@@ -229,7 +259,7 @@ class LanguageServerPlugin {
|
|
|
229
259
|
},
|
|
230
260
|
});
|
|
231
261
|
}
|
|
232
|
-
async
|
|
262
|
+
async sendChanges(contentChanges) {
|
|
233
263
|
if (!this.client.ready) {
|
|
234
264
|
return;
|
|
235
265
|
}
|
|
@@ -239,7 +269,7 @@ class LanguageServerPlugin {
|
|
|
239
269
|
uri: this.documentUri,
|
|
240
270
|
version: this.documentVersion++,
|
|
241
271
|
},
|
|
242
|
-
contentChanges
|
|
272
|
+
contentChanges,
|
|
243
273
|
});
|
|
244
274
|
}
|
|
245
275
|
catch (e) {
|
|
@@ -247,7 +277,7 @@ class LanguageServerPlugin {
|
|
|
247
277
|
}
|
|
248
278
|
}
|
|
249
279
|
requestDiagnostics(view) {
|
|
250
|
-
this.
|
|
280
|
+
this.sendChanges([{ text: view.state.doc.toString() }]);
|
|
251
281
|
}
|
|
252
282
|
async requestHoverTooltip(view, { line, character }) {
|
|
253
283
|
if (!this.client.ready || !this.client.capabilities.hoverProvider) {
|
|
@@ -290,9 +320,6 @@ class LanguageServerPlugin {
|
|
|
290
320
|
!this.client.capabilities.completionProvider) {
|
|
291
321
|
return null;
|
|
292
322
|
}
|
|
293
|
-
this.sendChange({
|
|
294
|
-
documentText: context.state.doc.toString(),
|
|
295
|
-
});
|
|
296
323
|
const result = await this.client.textDocumentCompletion({
|
|
297
324
|
textDocument: { uri: this.documentUri },
|
|
298
325
|
position: { line, character },
|
|
@@ -621,6 +648,7 @@ function languageServerWithTransport(options) {
|
|
|
621
648
|
documentUri: options.documentUri,
|
|
622
649
|
languageId: options.languageId,
|
|
623
650
|
allowHTMLContent: options.allowHTMLContent,
|
|
651
|
+
synchronizationMethod: options.synchronizationMethod,
|
|
624
652
|
}),
|
|
625
653
|
hoverTooltip(),
|
|
626
654
|
autocompletion(),
|
|
@@ -629,4 +657,4 @@ function languageServerWithTransport(options) {
|
|
|
629
657
|
];
|
|
630
658
|
}
|
|
631
659
|
|
|
632
|
-
export { LanguageServerClient, jumpToDefinition, jumpToDefinitionKeymap, jumpToDefinitionPos, languageServer, languageServerPlugin, languageServerWithTransport };
|
|
660
|
+
export { LanguageServerClient, SynchronizationMethod, jumpToDefinition, jumpToDefinitionKeymap, jumpToDefinitionPos, languageServer, languageServerPlugin, languageServerWithTransport };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -77,6 +77,10 @@ export declare class LanguageServerClient<InitializationOptions = unknown> {
|
|
|
77
77
|
protected notify<K extends keyof LSPNotifyMap>(method: K, params: LSPNotifyMap[K]): Promise<LSPNotifyMap[K]>;
|
|
78
78
|
protected processNotification(notification: Notification): void;
|
|
79
79
|
}
|
|
80
|
+
export declare enum SynchronizationMethod {
|
|
81
|
+
Full = "full",
|
|
82
|
+
Incremental = "incremental"
|
|
83
|
+
}
|
|
80
84
|
export declare class LanguageServerPlugin implements PluginValue {
|
|
81
85
|
private view;
|
|
82
86
|
client: LanguageServerClient;
|
|
@@ -84,21 +88,20 @@ export declare class LanguageServerPlugin implements PluginValue {
|
|
|
84
88
|
private languageId;
|
|
85
89
|
private documentVersion;
|
|
86
90
|
private allowHTMLContent;
|
|
87
|
-
private
|
|
88
|
-
constructor(view: EditorView, { client, documentUri, languageId, allowHTMLContent, }: {
|
|
91
|
+
private synchronizationMethod;
|
|
92
|
+
constructor(view: EditorView, { client, documentUri, languageId, allowHTMLContent, synchronizationMethod, }: {
|
|
89
93
|
client: LanguageServerClient;
|
|
90
94
|
documentUri: string;
|
|
91
95
|
languageId: string;
|
|
92
96
|
allowHTMLContent: boolean;
|
|
97
|
+
synchronizationMethod: SynchronizationMethod;
|
|
93
98
|
});
|
|
94
|
-
update({ docChanged }: ViewUpdate): void;
|
|
99
|
+
update({ state, changes, startState, docChanged }: ViewUpdate): void;
|
|
95
100
|
destroy(): void;
|
|
96
101
|
initialize({ documentText }: {
|
|
97
102
|
documentText: string;
|
|
98
103
|
}): Promise<void>;
|
|
99
|
-
|
|
100
|
-
documentText: string;
|
|
101
|
-
}): Promise<void>;
|
|
104
|
+
sendChanges(contentChanges: LSP.TextDocumentContentChangeEvent[]): Promise<void>;
|
|
102
105
|
requestDiagnostics(view: EditorView): void;
|
|
103
106
|
requestHoverTooltip(view: EditorView, { line, character }: {
|
|
104
107
|
line: number;
|
|
@@ -147,6 +150,7 @@ export declare const languageServerPlugin: ViewPlugin<LanguageServerPlugin, {
|
|
|
147
150
|
documentUri: string;
|
|
148
151
|
languageId: string;
|
|
149
152
|
allowHTMLContent: boolean;
|
|
153
|
+
synchronizationMethod: SynchronizationMethod;
|
|
150
154
|
}>;
|
|
151
155
|
export interface LanguageServerBaseOptions {
|
|
152
156
|
rootUri: string | null;
|