codemirror-languageserver 1.4.1 → 1.5.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 +13 -1
- package/dist/index.d.sync-conflict-20210813-102235-QZ53W3J.ts +10 -0
- package/dist/index.js +12 -9
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -8,6 +8,10 @@ This plugin enables code completion, hover tooltips, and linter functionality by
|
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
|
+
```
|
|
12
|
+
npm i codemirror-languageserver
|
|
13
|
+
```
|
|
14
|
+
|
|
11
15
|
``` js
|
|
12
16
|
import { languageServer } from 'codemirror-languageserver';
|
|
13
17
|
|
|
@@ -22,7 +26,7 @@ var view = new EditorView({
|
|
|
22
26
|
state: EditorState.create({
|
|
23
27
|
extensions: [
|
|
24
28
|
// ...
|
|
25
|
-
ls
|
|
29
|
+
ls,
|
|
26
30
|
// ...
|
|
27
31
|
]
|
|
28
32
|
})
|
|
@@ -33,6 +37,14 @@ var view = new EditorView({
|
|
|
33
37
|
|
|
34
38
|
Contributions are welcome.
|
|
35
39
|
|
|
40
|
+
## Real World Uses
|
|
41
|
+
|
|
42
|
+
https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8ada-9b7b7a1e4ade.mp4
|
|
43
|
+
|
|
44
|
+
| | |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| [Toph](https://toph.co) | Competitive programming platform |
|
|
47
|
+
|
|
36
48
|
## License
|
|
37
49
|
|
|
38
50
|
The library is available under the BSD (3-Clause) License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface LanguageServerOptions {
|
|
2
|
+
serverUri: `ws://${string}` | `wss://${string}`;
|
|
3
|
+
rootUri: string;
|
|
4
|
+
documentUri: string;
|
|
5
|
+
languageId: string;
|
|
6
|
+
onConnect(): void;
|
|
7
|
+
onDisconnect(): void;
|
|
8
|
+
}
|
|
9
|
+
declare function languageServer(options: LanguageServerOptions): import("@codemirror/state").Extension[];
|
|
10
|
+
export { languageServer };
|
package/dist/index.js
CHANGED
|
@@ -46,14 +46,14 @@ class LanguageServerPlugin {
|
|
|
46
46
|
destroy() {
|
|
47
47
|
this.client.close();
|
|
48
48
|
}
|
|
49
|
-
request(
|
|
49
|
+
request(method, params, timeout) {
|
|
50
50
|
return this.client.request({ method, params }, timeout);
|
|
51
51
|
}
|
|
52
52
|
notify(method, params) {
|
|
53
53
|
return this.client.notify({ method, params });
|
|
54
54
|
}
|
|
55
55
|
async initialize({ documentText }) {
|
|
56
|
-
const { capabilities } = await this.request(
|
|
56
|
+
const { capabilities } = await this.request('initialize', {
|
|
57
57
|
capabilities: {
|
|
58
58
|
textDocument: {
|
|
59
59
|
hover: {
|
|
@@ -116,7 +116,7 @@ class LanguageServerPlugin {
|
|
|
116
116
|
uri: this.rootUri,
|
|
117
117
|
},
|
|
118
118
|
],
|
|
119
|
-
});
|
|
119
|
+
}, timeout * 3);
|
|
120
120
|
this.capabilities = capabilities;
|
|
121
121
|
this.notify('initialized', {});
|
|
122
122
|
this.notify('textDocument/didOpen', {
|
|
@@ -152,10 +152,10 @@ class LanguageServerPlugin {
|
|
|
152
152
|
if (!this.ready || !this.capabilities.hoverProvider)
|
|
153
153
|
return null;
|
|
154
154
|
this.sendChange({ documentText: view.state.doc.toString() });
|
|
155
|
-
const result = await this.request(
|
|
155
|
+
const result = await this.request('textDocument/hover', {
|
|
156
156
|
textDocument: { uri: this.documentUri },
|
|
157
157
|
position: { line, character },
|
|
158
|
-
});
|
|
158
|
+
}, timeout);
|
|
159
159
|
if (!result)
|
|
160
160
|
return null;
|
|
161
161
|
const { contents, range } = result;
|
|
@@ -178,14 +178,14 @@ class LanguageServerPlugin {
|
|
|
178
178
|
this.sendChange({
|
|
179
179
|
documentText: context.state.doc.toString(),
|
|
180
180
|
});
|
|
181
|
-
const result = await this.request(
|
|
181
|
+
const result = await this.request('textDocument/completion', {
|
|
182
182
|
textDocument: { uri: this.documentUri },
|
|
183
183
|
position: { line, character },
|
|
184
184
|
context: {
|
|
185
185
|
triggerKind,
|
|
186
186
|
triggerCharacter,
|
|
187
187
|
},
|
|
188
|
-
});
|
|
188
|
+
}, timeout);
|
|
189
189
|
if (!result)
|
|
190
190
|
return null;
|
|
191
191
|
const items = 'items' in result ? result.items : result;
|
|
@@ -255,7 +255,7 @@ class LanguageServerPlugin {
|
|
|
255
255
|
}[severity],
|
|
256
256
|
message,
|
|
257
257
|
}))
|
|
258
|
-
.filter(({ from, to }) => from !== null && to !== null)
|
|
258
|
+
.filter(({ from, to }) => from !== null && to !== null && from !== undefined && to !== undefined)
|
|
259
259
|
.sort((a, b) => {
|
|
260
260
|
switch (true) {
|
|
261
261
|
case a.from < b.from:
|
|
@@ -312,7 +312,10 @@ function languageServer(options) {
|
|
|
312
312
|
function posToOffset(doc, pos) {
|
|
313
313
|
if (pos.line >= doc.lines)
|
|
314
314
|
return;
|
|
315
|
-
|
|
315
|
+
const offset = doc.line(pos.line + 1).from + pos.character;
|
|
316
|
+
if (offset > doc.length)
|
|
317
|
+
return;
|
|
318
|
+
return offset;
|
|
316
319
|
}
|
|
317
320
|
function offsetToPos(doc, offset) {
|
|
318
321
|
const line = doc.lineAt(offset);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codemirror-languageserver",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Language Server Plugin for CodeMirror 6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"prepare": "rollup
|
|
7
|
+
"prepare": "rollup -c rollup.config.js"
|
|
8
8
|
},
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Mahmud Ridwan",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"typescript": "^4.2.4"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@codemirror/autocomplete": "^0.
|
|
34
|
-
"@codemirror/lint": "^0.
|
|
35
|
-
"@codemirror/state": "^0.
|
|
36
|
-
"@codemirror/tooltip": "^0.
|
|
37
|
-
"@codemirror/view": "^0.
|
|
33
|
+
"@codemirror/autocomplete": "^0.19.8",
|
|
34
|
+
"@codemirror/lint": "^0.19.3",
|
|
35
|
+
"@codemirror/state": "^0.19.6",
|
|
36
|
+
"@codemirror/tooltip": "^0.19.7",
|
|
37
|
+
"@codemirror/view": "^0.19.19",
|
|
38
38
|
"@open-rpc/client-js": "^1.6.2",
|
|
39
39
|
"vscode-languageserver-protocol": "^3.16.0"
|
|
40
40
|
},
|