codemirror-languageserver 1.17.0 → 1.18.0
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 +45 -19
- 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,41 @@ 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 = synchronizationMethod;
|
|
196
222
|
this.documentVersion = 0;
|
|
197
|
-
this.changesTimeout = 0;
|
|
198
223
|
this.client.attachPlugin(this);
|
|
199
224
|
this.initialize({
|
|
200
225
|
documentText: this.view.state.doc.toString(),
|
|
201
226
|
});
|
|
202
227
|
}
|
|
203
|
-
update({ docChanged }) {
|
|
228
|
+
update({ state, changes, startState, docChanged }) {
|
|
204
229
|
if (!docChanged) {
|
|
205
230
|
return;
|
|
206
231
|
}
|
|
207
|
-
|
|
208
|
-
|
|
232
|
+
switch (this.synchronizationMethod) {
|
|
233
|
+
case SynchronizationMethod.Full:
|
|
234
|
+
this.sendChanges([
|
|
235
|
+
{
|
|
236
|
+
text: this.view.state.doc.toString(),
|
|
237
|
+
},
|
|
238
|
+
]);
|
|
239
|
+
break;
|
|
240
|
+
case SynchronizationMethod.Incremental:
|
|
241
|
+
this.sendChanges(changeSetToEvents(startState.doc, changes));
|
|
242
|
+
break;
|
|
209
243
|
}
|
|
210
|
-
this.changesTimeout = self.setTimeout(() => {
|
|
211
|
-
this.sendChange({
|
|
212
|
-
documentText: this.view.state.doc.toString(),
|
|
213
|
-
});
|
|
214
|
-
}, changesDelay);
|
|
215
244
|
}
|
|
216
245
|
destroy() {
|
|
217
246
|
this.client.detachPlugin(this);
|
|
@@ -229,7 +258,7 @@ class LanguageServerPlugin {
|
|
|
229
258
|
},
|
|
230
259
|
});
|
|
231
260
|
}
|
|
232
|
-
async
|
|
261
|
+
async sendChanges(contentChanges) {
|
|
233
262
|
if (!this.client.ready) {
|
|
234
263
|
return;
|
|
235
264
|
}
|
|
@@ -239,7 +268,7 @@ class LanguageServerPlugin {
|
|
|
239
268
|
uri: this.documentUri,
|
|
240
269
|
version: this.documentVersion++,
|
|
241
270
|
},
|
|
242
|
-
contentChanges
|
|
271
|
+
contentChanges,
|
|
243
272
|
});
|
|
244
273
|
}
|
|
245
274
|
catch (e) {
|
|
@@ -247,13 +276,12 @@ class LanguageServerPlugin {
|
|
|
247
276
|
}
|
|
248
277
|
}
|
|
249
278
|
requestDiagnostics(view) {
|
|
250
|
-
this.
|
|
279
|
+
this.sendChanges([{ text: view.state.doc.toString() }]);
|
|
251
280
|
}
|
|
252
281
|
async requestHoverTooltip(view, { line, character }) {
|
|
253
282
|
if (!this.client.ready || !this.client.capabilities.hoverProvider) {
|
|
254
283
|
return null;
|
|
255
284
|
}
|
|
256
|
-
this.sendChange({ documentText: view.state.doc.toString() });
|
|
257
285
|
const result = await this.client.textDocumentHover({
|
|
258
286
|
textDocument: { uri: this.documentUri },
|
|
259
287
|
position: { line, character },
|
|
@@ -291,9 +319,6 @@ class LanguageServerPlugin {
|
|
|
291
319
|
!this.client.capabilities.completionProvider) {
|
|
292
320
|
return null;
|
|
293
321
|
}
|
|
294
|
-
this.sendChange({
|
|
295
|
-
documentText: context.state.doc.toString(),
|
|
296
|
-
});
|
|
297
322
|
const result = await this.client.textDocumentCompletion({
|
|
298
323
|
textDocument: { uri: this.documentUri },
|
|
299
324
|
position: { line, character },
|
|
@@ -622,6 +647,7 @@ function languageServerWithTransport(options) {
|
|
|
622
647
|
documentUri: options.documentUri,
|
|
623
648
|
languageId: options.languageId,
|
|
624
649
|
allowHTMLContent: options.allowHTMLContent,
|
|
650
|
+
synchronizationMethod: options.synchronizationMethod,
|
|
625
651
|
}),
|
|
626
652
|
hoverTooltip(),
|
|
627
653
|
autocompletion(),
|
|
@@ -630,4 +656,4 @@ function languageServerWithTransport(options) {
|
|
|
630
656
|
];
|
|
631
657
|
}
|
|
632
658
|
|
|
633
|
-
export { LanguageServerClient, jumpToDefinition, jumpToDefinitionKeymap, jumpToDefinitionPos, languageServer, languageServerPlugin, languageServerWithTransport };
|
|
659
|
+
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;
|