codemirror-languageserver 1.13.0 → 1.15.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 CHANGED
@@ -12,37 +12,48 @@ This plugin enables code completion, hover tooltips, and linter functionality by
12
12
  npm i codemirror-languageserver
13
13
  ```
14
14
 
15
- ``` js
15
+ ```js
16
16
  import { languageServer } from 'codemirror-languageserver';
17
17
 
18
- const transport = new WebSocketTransport(serverUri)
18
+ const transport = new WebSocketTransport(serverUri);
19
19
 
20
20
  var ls = languageServer({
21
- // WebSocket server uri and other client options.
22
- serverUri,
23
- rootUri: 'file:///',
24
-
25
- // Alternatively, to share the same client across multiple instances of this plugin.
26
- client: new LanguageServerClient({
27
- serverUri,
28
- rootUri: 'file:///'
29
- }),
30
-
31
- documentUri: `file:///${filename}`,
32
- languageId: 'cpp' // As defined at https://microsoft.github.io/language-server-protocol/specification#textDocumentItem.
21
+ // WebSocket server uri and other client options.
22
+ serverUri,
23
+ rootUri: 'file:///',
24
+
25
+ // Alternatively, to share the same client across multiple instances of this plugin.
26
+ client: new LanguageServerClient({
27
+ serverUri,
28
+ rootUri: 'file:///',
29
+ }),
30
+
31
+ documentUri: `file:///${filename}`,
32
+ languageId: 'cpp', // As defined at https://microsoft.github.io/language-server-protocol/specification#textDocumentItem.
33
33
  });
34
34
 
35
35
  var view = new EditorView({
36
- state: EditorState.create({
37
- extensions: [
38
- // ...
39
- ls,
40
- // ...
41
- ]
42
- })
36
+ state: EditorState.create({
37
+ extensions: [
38
+ // ...
39
+ ls,
40
+ // ...
41
+ ],
42
+ }),
43
43
  });
44
44
  ```
45
45
 
46
+ ### Using with Initialization Options
47
+
48
+ The plugin includes built-in TypeScript definitions for popular language servers:
49
+
50
+ - `PyrightInitializationOptions` - Python (Pyright)
51
+ - `RustAnalyzerInitializationOptions` - Rust (rust-analyzer)
52
+ - `TypeScriptInitializationOptions` - TypeScript/JavaScript
53
+ - `ESLintInitializationOptions` - ESLint
54
+ - `ClangdInitializationOptions` - C/C++ (Clangd)
55
+ - `GoplsInitializationOptions` - Go (Gopls)
56
+
46
57
  ## Contributing
47
58
 
48
59
  Contributions are welcome.
@@ -51,7 +62,7 @@ Contributions are welcome.
51
62
 
52
63
  https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8ada-9b7b7a1e4ade.mp4
53
64
 
54
- - [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
65
+ - [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
55
66
 
56
67
  ## License
57
68
 
package/demo/demo.js ADDED
@@ -0,0 +1,100 @@
1
+ import {
2
+ EditorView,
3
+ highlightSpecialChars,
4
+ drawSelection,
5
+ highlightActiveLine,
6
+ keymap,
7
+ lineNumbers,
8
+ panels,
9
+ rectangularSelection,
10
+ } from '@codemirror/view';
11
+ import { EditorState, Compartment } from '@codemirror/state';
12
+ import {
13
+ indentOnInput,
14
+ indentUnit,
15
+ bracketMatching,
16
+ foldGutter,
17
+ foldKeymap,
18
+ defaultHighlightStyle,
19
+ syntaxHighlighting,
20
+ } from '@codemirror/language';
21
+ import {
22
+ defaultKeymap,
23
+ indentWithTab,
24
+ history,
25
+ historyKeymap,
26
+ } from '@codemirror/commands';
27
+ import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
28
+ import {
29
+ completionKeymap,
30
+ closeBrackets,
31
+ closeBracketsKeymap,
32
+ } from '@codemirror/autocomplete';
33
+ import { lintKeymap } from '@codemirror/lint';
34
+ import { cpp } from '@codemirror/lang-cpp';
35
+ import {
36
+ languageServer,
37
+ jumpToDefinitionKeymap,
38
+ jumpToDefinitionPos,
39
+ } from '../src';
40
+
41
+ const tabSizeCompartment = new Compartment();
42
+
43
+ const view = new EditorView({
44
+ doc: '#include <iostream>\n\nusing namespace std;\n\nint main() {\n\treturn 0;\n}\n',
45
+ parent: document.getElementById('editor'),
46
+ extensions: [
47
+ lineNumbers(),
48
+ highlightSpecialChars(),
49
+ history(),
50
+ foldGutter(),
51
+ drawSelection(),
52
+ EditorState.allowMultipleSelections.of(true),
53
+ indentOnInput(),
54
+ indentUnit.of('\t'),
55
+ syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
56
+ bracketMatching(),
57
+ closeBrackets(),
58
+ rectangularSelection(),
59
+ highlightActiveLine(),
60
+ highlightSelectionMatches(),
61
+ panels(),
62
+ keymap.of([
63
+ ...closeBracketsKeymap,
64
+ ...defaultKeymap,
65
+ indentWithTab,
66
+ ...searchKeymap,
67
+ ...historyKeymap,
68
+ ...foldKeymap,
69
+ ...completionKeymap,
70
+ ...lintKeymap,
71
+ ]),
72
+ tabSizeCompartment.of(EditorState.tabSize.of(4)),
73
+ cpp(),
74
+ languageServer({
75
+ serverUri: 'ws://localhost:3000/?stack=clangd11',
76
+ allowHTMLContent: true,
77
+ rootUri: 'file:///demo',
78
+ workspaceFolders: [
79
+ {
80
+ name: 'root',
81
+ uri: 'file:///demo',
82
+ },
83
+ ],
84
+ documentUri: `file:///demo/main.cpp`,
85
+ languageId: 'cpp',
86
+ }),
87
+ keymap.of([...jumpToDefinitionKeymap]),
88
+ EditorView.domEventHandlers({
89
+ click: (event, view) => {
90
+ if (!event.ctrlKey && !event.metaKey) return;
91
+ const pos = view.posAtCoords({
92
+ x: event.clientX,
93
+ y: event.clientY,
94
+ });
95
+ const ok = jumpToDefinitionPos(pos)(view);
96
+ if (ok) event.preventDefault();
97
+ },
98
+ }),
99
+ ],
100
+ });