codemirror-languageserver 1.9.0 → 1.11.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/README.md +1 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +12 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,9 +51,7 @@ Contributions are welcome.
|
|
|
51
51
|
|
|
52
52
|
https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8ada-9b7b7a1e4ade.mp4
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
| --- | --- |
|
|
56
|
-
| [Toph](https://toph.co) | Competitive programming platform |
|
|
54
|
+
- [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
|
|
57
55
|
|
|
58
56
|
## License
|
|
59
57
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare class LanguageServerClient {
|
|
|
24
24
|
ready: boolean;
|
|
25
25
|
capabilities: LSP.ServerCapabilities<any>;
|
|
26
26
|
private plugins;
|
|
27
|
+
initializePromise: Promise<void>;
|
|
27
28
|
constructor(options: LanguageServerClientOptions);
|
|
28
29
|
initialize(): Promise<void>;
|
|
29
30
|
close(): void;
|
|
@@ -39,12 +40,13 @@ declare class LanguageServerClient {
|
|
|
39
40
|
}
|
|
40
41
|
declare class LanguageServerPlugin implements PluginValue {
|
|
41
42
|
private view;
|
|
43
|
+
private allowHTMLContent;
|
|
42
44
|
client: LanguageServerClient;
|
|
43
45
|
private documentUri;
|
|
44
46
|
private languageId;
|
|
45
47
|
private documentVersion;
|
|
46
48
|
private changesTimeout;
|
|
47
|
-
constructor(view: EditorView);
|
|
49
|
+
constructor(view: EditorView, allowHTMLContent: boolean);
|
|
48
50
|
update({ docChanged }: ViewUpdate): void;
|
|
49
51
|
destroy(): void;
|
|
50
52
|
initialize({ documentText }: {
|
|
@@ -80,6 +82,7 @@ interface LanguageServerClientOptions extends LanguageServerBaseOptions {
|
|
|
80
82
|
}
|
|
81
83
|
interface LanguageServerOptions extends LanguageServerClientOptions {
|
|
82
84
|
client?: LanguageServerClient;
|
|
85
|
+
allowHTMLContent?: boolean;
|
|
83
86
|
}
|
|
84
87
|
interface LanguageServerWebsocketOptions extends LanguageServerBaseOptions {
|
|
85
88
|
serverUri: `ws://${string}` | `wss://${string}`;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { autocompletion } from '@codemirror/autocomplete';
|
|
2
2
|
import { setDiagnostics } from '@codemirror/lint';
|
|
3
3
|
import { Facet } from '@codemirror/state';
|
|
4
|
-
import {
|
|
4
|
+
import { ViewPlugin, hoverTooltip } from '@codemirror/view';
|
|
5
5
|
import { RequestManager, Client, WebSocketTransport } from '@open-rpc/client-js';
|
|
6
6
|
import { CompletionItemKind, CompletionTriggerKind, DiagnosticSeverity } from 'vscode-languageserver-protocol';
|
|
7
7
|
|
|
@@ -39,7 +39,7 @@ class LanguageServerClient {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
this.initialize();
|
|
42
|
+
this.initializePromise = this.initialize();
|
|
43
43
|
}
|
|
44
44
|
async initialize() {
|
|
45
45
|
const { capabilities } = await this.request('initialize', {
|
|
@@ -143,8 +143,9 @@ class LanguageServerClient {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
class LanguageServerPlugin {
|
|
146
|
-
constructor(view) {
|
|
146
|
+
constructor(view, allowHTMLContent) {
|
|
147
147
|
this.view = view;
|
|
148
|
+
this.allowHTMLContent = allowHTMLContent;
|
|
148
149
|
this.client = this.view.state.facet(client);
|
|
149
150
|
this.documentUri = this.view.state.facet(documentUri);
|
|
150
151
|
this.languageId = this.view.state.facet(languageId);
|
|
@@ -170,6 +171,9 @@ class LanguageServerPlugin {
|
|
|
170
171
|
this.client.detachPlugin(this);
|
|
171
172
|
}
|
|
172
173
|
async initialize({ documentText }) {
|
|
174
|
+
if (this.client.initializePromise) {
|
|
175
|
+
await this.client.initializePromise;
|
|
176
|
+
}
|
|
173
177
|
this.client.textDocumentDidOpen({
|
|
174
178
|
textDocument: {
|
|
175
179
|
uri: this.documentUri,
|
|
@@ -219,7 +223,10 @@ class LanguageServerPlugin {
|
|
|
219
223
|
return null;
|
|
220
224
|
const dom = document.createElement('div');
|
|
221
225
|
dom.classList.add('documentation');
|
|
222
|
-
|
|
226
|
+
if (this.allowHTMLContent)
|
|
227
|
+
dom.innerHTML = formatContents(contents);
|
|
228
|
+
else
|
|
229
|
+
dom.textContent = formatContents(contents);
|
|
223
230
|
return { pos, end, create: (view) => ({ dom }), above: true };
|
|
224
231
|
}
|
|
225
232
|
async requestCompletion(context, { line, character }, { triggerKind, triggerCharacter, }) {
|
|
@@ -334,7 +341,7 @@ function languageServerWithTransport(options) {
|
|
|
334
341
|
client.of(options.client || new LanguageServerClient({ ...options, autoClose: true })),
|
|
335
342
|
documentUri.of(options.documentUri),
|
|
336
343
|
languageId.of(options.languageId),
|
|
337
|
-
ViewPlugin.define((view) => (plugin = new LanguageServerPlugin(view))),
|
|
344
|
+
ViewPlugin.define((view) => (plugin = new LanguageServerPlugin(view, options.allowHTMLContent))),
|
|
338
345
|
hoverTooltip((view, pos) => {
|
|
339
346
|
var _a;
|
|
340
347
|
return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.requestHoverTooltip(view, offsetToPos(view.state.doc, pos))) !== null && _a !== void 0 ? _a : null;
|
|
@@ -365,7 +372,6 @@ function languageServerWithTransport(options) {
|
|
|
365
372
|
},
|
|
366
373
|
],
|
|
367
374
|
}),
|
|
368
|
-
baseTheme,
|
|
369
375
|
];
|
|
370
376
|
}
|
|
371
377
|
function posToOffset(doc, pos) {
|
|
@@ -417,17 +423,5 @@ function prefixMatch(options) {
|
|
|
417
423
|
const source = toSet(first) + toSet(rest) + '*$';
|
|
418
424
|
return [new RegExp('^' + source), new RegExp(source)];
|
|
419
425
|
}
|
|
420
|
-
const baseTheme = EditorView.baseTheme({
|
|
421
|
-
'.cm-tooltip.documentation': {
|
|
422
|
-
display: 'block',
|
|
423
|
-
marginLeft: '0',
|
|
424
|
-
padding: '3px 6px 3px 8px',
|
|
425
|
-
borderLeft: '5px solid #999',
|
|
426
|
-
whiteSpace: 'pre',
|
|
427
|
-
},
|
|
428
|
-
'.cm-tooltip.lint': {
|
|
429
|
-
whiteSpace: 'pre',
|
|
430
|
-
},
|
|
431
|
-
});
|
|
432
426
|
|
|
433
427
|
export { LanguageServerClient, languageServer, languageServerWithTransport };
|