codemirror-languageserver 1.10.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 +3 -1
- package/dist/index.js +8 -17
- 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
|
@@ -40,12 +40,13 @@ declare class LanguageServerClient {
|
|
|
40
40
|
}
|
|
41
41
|
declare class LanguageServerPlugin implements PluginValue {
|
|
42
42
|
private view;
|
|
43
|
+
private allowHTMLContent;
|
|
43
44
|
client: LanguageServerClient;
|
|
44
45
|
private documentUri;
|
|
45
46
|
private languageId;
|
|
46
47
|
private documentVersion;
|
|
47
48
|
private changesTimeout;
|
|
48
|
-
constructor(view: EditorView);
|
|
49
|
+
constructor(view: EditorView, allowHTMLContent: boolean);
|
|
49
50
|
update({ docChanged }: ViewUpdate): void;
|
|
50
51
|
destroy(): void;
|
|
51
52
|
initialize({ documentText }: {
|
|
@@ -81,6 +82,7 @@ interface LanguageServerClientOptions extends LanguageServerBaseOptions {
|
|
|
81
82
|
}
|
|
82
83
|
interface LanguageServerOptions extends LanguageServerClientOptions {
|
|
83
84
|
client?: LanguageServerClient;
|
|
85
|
+
allowHTMLContent?: boolean;
|
|
84
86
|
}
|
|
85
87
|
interface LanguageServerWebsocketOptions extends LanguageServerBaseOptions {
|
|
86
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
|
|
|
@@ -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);
|
|
@@ -222,7 +223,10 @@ class LanguageServerPlugin {
|
|
|
222
223
|
return null;
|
|
223
224
|
const dom = document.createElement('div');
|
|
224
225
|
dom.classList.add('documentation');
|
|
225
|
-
|
|
226
|
+
if (this.allowHTMLContent)
|
|
227
|
+
dom.innerHTML = formatContents(contents);
|
|
228
|
+
else
|
|
229
|
+
dom.textContent = formatContents(contents);
|
|
226
230
|
return { pos, end, create: (view) => ({ dom }), above: true };
|
|
227
231
|
}
|
|
228
232
|
async requestCompletion(context, { line, character }, { triggerKind, triggerCharacter, }) {
|
|
@@ -337,7 +341,7 @@ function languageServerWithTransport(options) {
|
|
|
337
341
|
client.of(options.client || new LanguageServerClient({ ...options, autoClose: true })),
|
|
338
342
|
documentUri.of(options.documentUri),
|
|
339
343
|
languageId.of(options.languageId),
|
|
340
|
-
ViewPlugin.define((view) => (plugin = new LanguageServerPlugin(view))),
|
|
344
|
+
ViewPlugin.define((view) => (plugin = new LanguageServerPlugin(view, options.allowHTMLContent))),
|
|
341
345
|
hoverTooltip((view, pos) => {
|
|
342
346
|
var _a;
|
|
343
347
|
return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.requestHoverTooltip(view, offsetToPos(view.state.doc, pos))) !== null && _a !== void 0 ? _a : null;
|
|
@@ -368,7 +372,6 @@ function languageServerWithTransport(options) {
|
|
|
368
372
|
},
|
|
369
373
|
],
|
|
370
374
|
}),
|
|
371
|
-
baseTheme,
|
|
372
375
|
];
|
|
373
376
|
}
|
|
374
377
|
function posToOffset(doc, pos) {
|
|
@@ -420,17 +423,5 @@ function prefixMatch(options) {
|
|
|
420
423
|
const source = toSet(first) + toSet(rest) + '*$';
|
|
421
424
|
return [new RegExp('^' + source), new RegExp(source)];
|
|
422
425
|
}
|
|
423
|
-
const baseTheme = EditorView.baseTheme({
|
|
424
|
-
'.cm-tooltip.documentation': {
|
|
425
|
-
display: 'block',
|
|
426
|
-
marginLeft: '0',
|
|
427
|
-
padding: '3px 6px 3px 8px',
|
|
428
|
-
borderLeft: '5px solid #999',
|
|
429
|
-
whiteSpace: 'pre',
|
|
430
|
-
},
|
|
431
|
-
'.cm-tooltip.lint': {
|
|
432
|
-
whiteSpace: 'pre',
|
|
433
|
-
},
|
|
434
|
-
});
|
|
435
426
|
|
|
436
427
|
export { LanguageServerClient, languageServer, languageServerWithTransport };
|