codemirror-languageserver 1.19.0 → 1.20.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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/codemirror-languageserver.svg)](https://www.npmjs.com/package/codemirror-languageserver)
4
4
 
5
- This plugin enables code completion, hover tooltips, and linter functionality by connecting a CodeMirror 6 editor with a language server over WebSocket.
5
+ This plugin connects a [CodeMirror 6](https://codemirror.net/) editor with a [Language Server](https://microsoft.github.io/language-server-protocol/) over WebSocket, providing IDE-like features in the browser.
6
6
 
7
7
  [How It Works](https://hjr265.me/blog/codemirror-lsp/)
8
8
 
@@ -18,61 +18,114 @@ https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8a
18
18
  - 🎨 Document Formatting and Range Formatting
19
19
  - ✏️ Rename Symbol
20
20
 
21
- ## Usage
21
+ ## Installation
22
22
 
23
23
  ```
24
24
  npm i codemirror-languageserver
25
25
  ```
26
26
 
27
+ **Peer dependencies:** This package requires `@codemirror/autocomplete`, `@codemirror/lint`, `@codemirror/state`, and `@codemirror/view` as peer dependencies. If you're using CodeMirror 6, you likely already have these installed.
28
+
29
+ ## Quick Start
30
+
27
31
  ```js
32
+ import { EditorState } from '@codemirror/state';
33
+ import { EditorView } from '@codemirror/view';
28
34
  import { languageServer } from 'codemirror-languageserver';
29
35
 
30
- var ls = languageServer({
31
- // WebSocket server uri and other client options.
32
- serverUri,
36
+ const ls = languageServer({
37
+ serverUri: 'ws://localhost:8080',
33
38
  rootUri: 'file:///',
34
-
35
- // Alternatively, to share the same client across multiple instances of this plugin.
36
- client: new LanguageServerClient({
37
- transport: new WebSocketTransport(serverUri),
38
- rootUri: 'file:///',
39
- }),
40
-
41
39
  documentUri: `file:///${filename}`,
42
40
  languageId: 'cpp', // As defined at https://microsoft.github.io/language-server-protocol/specification#textDocumentItem.
43
41
  });
44
42
 
45
- var view = new EditorView({
43
+ const view = new EditorView({
46
44
  state: EditorState.create({
47
45
  extensions: [
48
- // ...
46
+ // ... other extensions
49
47
  ls,
50
- // ...
51
48
  ],
52
49
  }),
53
50
  });
54
51
  ```
55
52
 
56
- ### Custom Transport
53
+ This sets up all built-in features: completion, hover, diagnostics, go-to-definition, document highlight, and rename support.
54
+
55
+ ## Options
56
+
57
+ | Option | Type | Description |
58
+ |---|---|---|
59
+ | `serverUri` | `ws://...` or `wss://...` | WebSocket server URI |
60
+ | `rootUri` | `string` | Root URI of the workspace |
61
+ | `workspaceFolders` | `WorkspaceFolder[]` | LSP workspace folders |
62
+ | `documentUri` | `string` | URI of the document being edited |
63
+ | `languageId` | `string` | Language identifier ([spec](https://microsoft.github.io/language-server-protocol/specification#textDocumentItem)) |
64
+ | `initializationOptions` | `object` | Server-specific initialization options |
65
+ | `locale` | `string` | Locale for the LSP session (e.g. `'en'`) |
66
+ | `allowHTMLContent` | `boolean` | Trust raw HTML in hover/completion content (default: `false`) |
67
+ | `synchronizationMethod` | `SynchronizationMethod` | `'full'` or `'incremental'` document sync (default: `'full'`) |
68
+ | `client` | `LanguageServerClient` | Share a client across multiple editor instances |
69
+ | `onCapabilities` | `(capabilities) => void` | Called when server capabilities are available |
70
+
71
+ ## Shared Client
72
+
73
+ To share the same language server connection across multiple editor instances:
74
+
75
+ ```js
76
+ import { LanguageServerClient, languageServerWithTransport, WebSocketTransport } from 'codemirror-languageserver';
77
+
78
+ const client = new LanguageServerClient({
79
+ transport: new WebSocketTransport('ws://localhost:8080'),
80
+ rootUri: 'file:///',
81
+ });
82
+
83
+ // Use the same client for multiple editors
84
+ const ls1 = languageServerWithTransport({
85
+ client,
86
+ documentUri: 'file:///main.cpp',
87
+ languageId: 'cpp',
88
+ });
89
+
90
+ const ls2 = languageServerWithTransport({
91
+ client,
92
+ documentUri: 'file:///utils.cpp',
93
+ languageId: 'cpp',
94
+ });
95
+ ```
96
+
97
+ ## Custom Transport
57
98
 
58
- Use `languageServerWithTransport` to provide a custom transport (e.g. for non-WebSocket connections):
99
+ Use `languageServerWithTransport` for non-WebSocket connections:
59
100
 
60
101
  ```js
61
102
  import { languageServerWithTransport } from 'codemirror-languageserver';
62
103
 
63
- var ls = languageServerWithTransport({
64
- transport: myCustomTransport, // Must implement the Transport interface
104
+ const ls = languageServerWithTransport({
105
+ transport: myCustomTransport,
65
106
  rootUri: 'file:///',
66
107
  documentUri: `file:///${filename}`,
67
108
  languageId: 'cpp',
68
109
  });
69
110
  ```
70
111
 
71
- The `Transport` interface requires `send`, `onMessage`, `onClose`, `onError`, and `close` methods. You can import `Transport` and `WebSocketTransport` from the package.
112
+ The `Transport` interface:
113
+
114
+ ```ts
115
+ interface Transport {
116
+ send(message: string): void;
117
+ onMessage(callback: (message: string) => void): void;
118
+ onClose(callback: () => void): void;
119
+ onError(callback: (error: Error) => void): void;
120
+ close(): void;
121
+ }
122
+ ```
72
123
 
73
- ### Document Highlight
124
+ You can import `Transport` and `WebSocketTransport` from the package.
74
125
 
75
- Document highlights are enabled by default. When the cursor is on a symbol, all occurrences are highlighted. Style them with CSS:
126
+ ## Document Highlight
127
+
128
+ Enabled by default. When the cursor is on a symbol, all occurrences in the document are highlighted. Style with CSS:
76
129
 
77
130
  ```css
78
131
  .cm-lsp-highlight-text,
@@ -80,21 +133,25 @@ Document highlights are enabled by default. When the cursor is on a symbol, all
80
133
  .cm-lsp-highlight-write { background-color: rgba(255, 165, 0, 0.3); }
81
134
  ```
82
135
 
83
- ### Formatting
136
+ The three classes correspond to [DocumentHighlightKind](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentHighlightKind): general text occurrences, read accesses, and write accesses.
137
+
138
+ ## Formatting
84
139
 
85
- `formatDocument` and `formatSelection` are CodeMirror commands that you can bind to keys:
140
+ `formatDocument` and `formatSelection` are CodeMirror [commands](https://codemirror.net/docs/ref/#view.Command) — bind them to keys:
86
141
 
87
142
  ```js
88
143
  import { keymap } from '@codemirror/view';
89
144
  import { formatDocument, formatSelection } from 'codemirror-languageserver';
90
145
 
91
- keymap.of([
146
+ const formattingKeymap = keymap.of([
92
147
  { key: 'Shift-Alt-f', run: formatDocument },
93
148
  { key: 'Ctrl-k Ctrl-f', run: formatSelection },
94
- ])
149
+ ]);
95
150
  ```
96
151
 
97
- To configure formatting options (tab size, spaces vs tabs, etc.), use the `formattingOptions` facet:
152
+ ### Formatting Options
153
+
154
+ Configure formatting with the `formattingOptions` facet. By default, `tabSize` is read from the editor state.
98
155
 
99
156
  ```js
100
157
  import { formattingOptions } from 'codemirror-languageserver';
@@ -105,36 +162,81 @@ formattingOptions.of({
105
162
  insertSpaces: true,
106
163
  trimTrailingWhitespace: true,
107
164
  insertFinalNewline: true,
165
+ trimFinalNewlines: true,
108
166
  })
109
167
  ```
110
168
 
111
- By default, `tabSize` is read from the editor state.
169
+ ## Rename Symbol
112
170
 
113
- ### Rename Symbol
114
-
115
- `renameSymbol` is a CodeMirror command that opens a rename prompt at the top of the editor:
171
+ `renameSymbol` is a CodeMirror command that opens a rename prompt at the top of the editor. If the server supports `prepareRename`, the current symbol name is used as the placeholder.
116
172
 
117
173
  ```js
118
174
  import { keymap } from '@codemirror/view';
119
175
  import { renameSymbol } from 'codemirror-languageserver';
120
176
 
121
- keymap.of([
177
+ const renameKeymap = keymap.of([
122
178
  { key: 'F2', run: renameSymbol },
123
- ])
179
+ ]);
124
180
  ```
125
181
 
126
- Style the rename panel with CSS using the `cm-lsp-rename-panel` and `cm-lsp-rename-input` classes.
182
+ Style the panel with CSS:
183
+
184
+ ```css
185
+ .cm-lsp-rename-panel {
186
+ padding: 4px 8px;
187
+ border-bottom: 1px solid #ddd;
188
+ }
189
+ .cm-lsp-rename-input {
190
+ font-family: inherit;
191
+ font-size: inherit;
192
+ }
193
+ ```
127
194
 
128
- ### Using with Initialization Options
195
+ ## Server Capabilities
129
196
 
130
- The plugin includes built-in TypeScript definitions for popular language servers:
197
+ Use the `onCapabilities` callback to react when the server finishes initializing — e.g. to show or hide toolbar buttons:
131
198
 
132
- - `PyrightInitializationOptions` - Python (Pyright)
133
- - `RustAnalyzerInitializationOptions` - Rust (rust-analyzer)
134
- - `TypeScriptInitializationOptions` - TypeScript/JavaScript
135
- - `ESLintInitializationOptions` - ESLint
136
- - `ClangdInitializationOptions` - C/C++ (Clangd)
137
- - `GoplsInitializationOptions` - Go (Gopls)
199
+ ```js
200
+ languageServer({
201
+ serverUri: 'ws://localhost:8080',
202
+ rootUri: 'file:///',
203
+ documentUri: `file:///${filename}`,
204
+ languageId: 'cpp',
205
+ onCapabilities(capabilities) {
206
+ // capabilities.documentFormattingProvider
207
+ // capabilities.renameProvider
208
+ // capabilities.completionProvider
209
+ // etc.
210
+ toolbar.update({ capabilities });
211
+ },
212
+ })
213
+ ```
214
+
215
+ ## Initialization Options
216
+
217
+ The package includes TypeScript definitions for popular language servers:
218
+
219
+ - `PyrightInitializationOptions` — Python (Pyright)
220
+ - `RustAnalyzerInitializationOptions` — Rust (rust-analyzer)
221
+ - `TypeScriptInitializationOptions` — TypeScript/JavaScript
222
+ - `ESLintInitializationOptions` — ESLint
223
+ - `ClangdInitializationOptions` — C/C++ (Clangd)
224
+ - `GoplsInitializationOptions` — Go (Gopls)
225
+
226
+ ```ts
227
+ import { languageServer } from 'codemirror-languageserver';
228
+ import type { ClangdInitializationOptions } from 'codemirror-languageserver';
229
+
230
+ const ls = languageServer<ClangdInitializationOptions>({
231
+ serverUri: 'ws://localhost:8080',
232
+ rootUri: 'file:///',
233
+ documentUri: 'file:///main.cpp',
234
+ languageId: 'cpp',
235
+ initializationOptions: {
236
+ // Type-checked options specific to Clangd
237
+ },
238
+ });
239
+ ```
138
240
 
139
241
  ## Contributing
140
242
 
@@ -142,7 +244,7 @@ Contributions are welcome.
142
244
 
143
245
  ## Real World Uses
144
246
 
145
- - [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
247
+ - [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
146
248
 
147
249
  ## License
148
250
 
@@ -1,8 +1,20 @@
1
1
  import { Command, KeyBinding } from '@codemirror/view';
2
+ /** Command: jump to the definition of the symbol at the cursor. */
2
3
  export declare const jumpToDefinition: Command;
4
+ /** Returns a command that jumps to the definition of the symbol at `pos`. */
3
5
  export declare const jumpToDefinitionPos: (pos: number) => Command;
6
+ /** Command: jump to the declaration of the symbol at the cursor. */
4
7
  export declare const jumpToDeclaration: Command;
8
+ /** Returns a command that jumps to the declaration of the symbol at `pos`. */
5
9
  export declare const jumpToDeclarationPos: (pos: number) => Command;
10
+ /** Command: jump to the type definition of the symbol at the cursor. */
6
11
  export declare const jumpToTypeDefinition: Command;
12
+ /** Returns a command that jumps to the type definition of the symbol at `pos`. */
7
13
  export declare const jumpToTypeDefinitionPos: (pos: number) => Command;
14
+ /**
15
+ * Default keymap for go-to-definition commands.
16
+ *
17
+ * - `F12` — jump to definition
18
+ * - `Mod-F12` — jump to type definition
19
+ */
8
20
  export declare const jumpToDefinitionKeymap: readonly KeyBinding[];
@@ -1,6 +1,14 @@
1
1
  import { Facet } from '@codemirror/state';
2
2
  import type { EditorView } from '@codemirror/view';
3
3
  import type * as LSP from 'vscode-languageserver-protocol';
4
+ /**
5
+ * Facet for configuring LSP formatting options (tab size, spaces vs tabs, etc.).
6
+ *
7
+ * Defaults to `{ tabSize: 4, insertSpaces: true }`. The `tabSize` falls back
8
+ * to the editor state's `tabSize` if not explicitly set.
9
+ */
4
10
  export declare const formattingOptions: Facet<LSP.FormattingOptions, LSP.FormattingOptions>;
11
+ /** Command: format the entire document using the language server. */
5
12
  export declare function formatDocument(view: EditorView): boolean;
13
+ /** Command: format the current selection using the language server. */
6
14
  export declare function formatSelection(view: EditorView): boolean;
@@ -1,2 +1,8 @@
1
1
  import { Extension } from '@codemirror/state';
2
+ /**
3
+ * Extension that highlights all occurrences of the symbol under the cursor.
4
+ *
5
+ * Applies CSS classes `cm-lsp-highlight-text`, `cm-lsp-highlight-read`, and
6
+ * `cm-lsp-highlight-write` based on the highlight kind returned by the server.
7
+ */
2
8
  export declare const documentHighlight: () => Extension;
package/dist/index.d.ts CHANGED
@@ -16,5 +16,16 @@ interface LanguageServerWebsocketOptions<InitializationOptions = unknown> extend
16
16
  serverUri: `ws://${string}` | `wss://${string}`;
17
17
  initializationOptions?: InitializationOptions;
18
18
  }
19
+ /**
20
+ * Creates a set of CodeMirror extensions that connect to a language server over WebSocket.
21
+ *
22
+ * Includes completion, hover, diagnostics, go-to-definition, document highlight,
23
+ * and rename support. This is the main entry point for most use cases.
24
+ */
19
25
  export declare function languageServer<InitializationOptions = unknown>(options: LanguageServerWebsocketOptions<InitializationOptions>): (import("@codemirror/state").Extension | import("@codemirror/state").StateField<string>)[];
26
+ /**
27
+ * Like {@link languageServer}, but accepts a custom {@link Transport} instead of a WebSocket URI.
28
+ *
29
+ * Use this when communicating with the language server over a non-WebSocket channel.
30
+ */
20
31
  export declare function languageServerWithTransport<InitializationOptions = unknown>(options: LanguageServerOptions<InitializationOptions>): (import("@codemirror/state").Extension | import("@codemirror/state").StateField<string>)[];
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { CompletionItemKind, DiagnosticSeverity, CompletionTriggerKind, Document
5
5
  import { marked } from 'marked';
6
6
  import { autocompletion as autocompletion$1 } from '@codemirror/autocomplete';
7
7
 
8
+ /** A {@link Transport} that communicates over a browser-native WebSocket. */
8
9
  class WebSocketTransport {
9
10
  constructor(uri) {
10
11
  this.connection = new WebSocket(uri);
@@ -164,6 +165,12 @@ Facet.define({
164
165
  });
165
166
  Facet.define({ combine: useLast });
166
167
  Facet.define({ combine: useLast });
168
+ /**
169
+ * Manages the JSON-RPC connection to a language server.
170
+ *
171
+ * Handles initialization, request/response routing, and notification dispatch.
172
+ * Can be shared across multiple editor instances via the `client` option.
173
+ */
167
174
  class LanguageServerClient {
168
175
  constructor(options) {
169
176
  this.options = options;
@@ -267,10 +274,12 @@ class LanguageServerClient {
267
274
  };
268
275
  }
269
276
  async initialize() {
277
+ var _a, _b;
270
278
  const { capabilities } = await this.request('initialize', this.getInitializeParams(), timeout * 3);
271
279
  this.capabilities = capabilities;
272
280
  this.notify('initialized', {});
273
281
  this.ready = true;
282
+ (_b = (_a = this.options).onCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, capabilities);
274
283
  }
275
284
  close() {
276
285
  this.client.close();
@@ -339,9 +348,12 @@ class LanguageServerClient {
339
348
  }
340
349
  }
341
350
  }
351
+ /** Controls how document changes are sent to the language server. */
342
352
  var SynchronizationMethod;
343
353
  (function (SynchronizationMethod) {
354
+ /** Send the full document text on every change. */
344
355
  SynchronizationMethod["Full"] = "full";
356
+ /** Send only the changed ranges. More efficient for large documents. */
345
357
  SynchronizationMethod["Incremental"] = "incremental";
346
358
  })(SynchronizationMethod || (SynchronizationMethod = {}));
347
359
  class LanguageServerPlugin {
@@ -735,15 +747,31 @@ function requestTypeDefinition(view, pos) {
735
747
  plugin.requestTypeDefinition(view, offsetToPos(view.state.doc, pos));
736
748
  return true;
737
749
  }
750
+ /** Command: jump to the definition of the symbol at the cursor. */
738
751
  const jumpToDefinition = (view) => requestDefinition(view, view.state.selection.main.head);
752
+ /** Returns a command that jumps to the definition of the symbol at `pos`. */
739
753
  const jumpToDefinitionPos = (pos) => (view) => requestDefinition(view, pos);
754
+ /** Command: jump to the type definition of the symbol at the cursor. */
740
755
  const jumpToTypeDefinition = (view) => requestTypeDefinition(view, view.state.selection.main.head);
756
+ /** Returns a command that jumps to the type definition of the symbol at `pos`. */
741
757
  const jumpToTypeDefinitionPos = (pos) => (view) => requestTypeDefinition(view, pos);
758
+ /**
759
+ * Default keymap for go-to-definition commands.
760
+ *
761
+ * - `F12` — jump to definition
762
+ * - `Mod-F12` — jump to type definition
763
+ */
742
764
  const jumpToDefinitionKeymap = [
743
765
  { key: 'F12', run: jumpToDefinition, preventDefault: true },
744
766
  { key: 'Mod-F12', run: jumpToTypeDefinition, preventDefault: true },
745
767
  ];
746
768
 
769
+ /**
770
+ * Facet for configuring LSP formatting options (tab size, spaces vs tabs, etc.).
771
+ *
772
+ * Defaults to `{ tabSize: 4, insertSpaces: true }`. The `tabSize` falls back
773
+ * to the editor state's `tabSize` if not explicitly set.
774
+ */
747
775
  const formattingOptions = Facet.define({
748
776
  combine(values) {
749
777
  return Object.assign({ tabSize: 4, insertSpaces: true }, ...values);
@@ -765,6 +793,7 @@ function applyTextEdits(view, edits) {
765
793
  }));
766
794
  view.dispatch(view.state.update({ changes }));
767
795
  }
796
+ /** Command: format the entire document using the language server. */
768
797
  function formatDocument(view) {
769
798
  var _a;
770
799
  const plugin = view.plugin(languageServerPlugin);
@@ -786,6 +815,7 @@ function formatDocument(view) {
786
815
  });
787
816
  return true;
788
817
  }
818
+ /** Command: format the current selection using the language server. */
789
819
  function formatSelection(view) {
790
820
  var _a;
791
821
  const plugin = view.plugin(languageServerPlugin);
@@ -920,6 +950,12 @@ async function performRename(view, newName) {
920
950
  applyWorkspaceEdit(view, result);
921
951
  }
922
952
  }
953
+ /**
954
+ * Command: open a rename prompt for the symbol at the cursor.
955
+ *
956
+ * Uses `textDocument/prepareRename` to pre-fill the current name if supported
957
+ * by the server. Press Enter to confirm or Escape to cancel.
958
+ */
923
959
  function renameSymbol(view) {
924
960
  var _a;
925
961
  const plugin = view.plugin(languageServerPlugin);
@@ -1088,6 +1124,12 @@ const highlightPlugin = ViewPlugin.fromClass(class {
1088
1124
  clearTimeout(this.pending);
1089
1125
  }
1090
1126
  });
1127
+ /**
1128
+ * Extension that highlights all occurrences of the symbol under the cursor.
1129
+ *
1130
+ * Applies CSS classes `cm-lsp-highlight-text`, `cm-lsp-highlight-read`, and
1131
+ * `cm-lsp-highlight-write` based on the highlight kind returned by the server.
1132
+ */
1091
1133
  const documentHighlight = () => [
1092
1134
  highlightField,
1093
1135
  highlightPlugin,
@@ -1109,6 +1151,12 @@ const mouseHandler = () => EditorView.domEventHandlers({
1109
1151
  },
1110
1152
  });
1111
1153
 
1154
+ /**
1155
+ * Creates a set of CodeMirror extensions that connect to a language server over WebSocket.
1156
+ *
1157
+ * Includes completion, hover, diagnostics, go-to-definition, document highlight,
1158
+ * and rename support. This is the main entry point for most use cases.
1159
+ */
1112
1160
  function languageServer(options) {
1113
1161
  const serverUri = options.serverUri;
1114
1162
  const { serverUri: _, ...optionsWithoutServerUri } = options;
@@ -1117,6 +1165,11 @@ function languageServer(options) {
1117
1165
  transport: new WebSocketTransport(serverUri),
1118
1166
  });
1119
1167
  }
1168
+ /**
1169
+ * Like {@link languageServer}, but accepts a custom {@link Transport} instead of a WebSocket URI.
1170
+ *
1171
+ * Use this when communicating with the language server over a non-WebSocket channel.
1172
+ */
1120
1173
  function languageServerWithTransport(options) {
1121
1174
  return [
1122
1175
  languageServerPlugin.of({
package/dist/jsonrpc.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Interface for sending and receiving JSON-RPC messages.
3
+ *
4
+ * Implement this to use a custom communication channel (e.g. Web Workers,
5
+ * MessagePort, or HTTP). See {@link WebSocketTransport} for a reference
6
+ * implementation.
7
+ */
1
8
  export interface Transport {
2
9
  send(message: string): void;
3
10
  onMessage(callback: (message: string) => void): void;
@@ -5,6 +12,7 @@ export interface Transport {
5
12
  onError(callback: (error: Error) => void): void;
6
13
  close(): void;
7
14
  }
15
+ /** A {@link Transport} that communicates over a browser-native WebSocket. */
8
16
  export declare class WebSocketTransport implements Transport {
9
17
  connection: WebSocket;
10
18
  constructor(uri: string);
package/dist/plugin.d.ts CHANGED
@@ -67,8 +67,16 @@ interface LanguageServerClientLocationMethods {
67
67
  textDocumentDeclaration(params: LSP.DeclarationParams): LSP.Location | LSP.Location[] | LSP.LocationLink[] | null;
68
68
  textDocumentTypeDefinition(params: LSP.TypeDefinitionParams): LSP.Location | LSP.Location[] | LSP.LocationLink[] | null;
69
69
  }
70
+ /**
71
+ * Manages the JSON-RPC connection to a language server.
72
+ *
73
+ * Handles initialization, request/response routing, and notification dispatch.
74
+ * Can be shared across multiple editor instances via the `client` option.
75
+ */
70
76
  export declare class LanguageServerClient<InitializationOptions = unknown> {
77
+ /** Whether the server has finished initializing. */
71
78
  ready: boolean;
79
+ /** The server's capabilities, available after initialization. */
72
80
  capabilities: LSP.ServerCapabilities<any>;
73
81
  initializePromise: Promise<void>;
74
82
  private rootUri;
@@ -104,8 +112,11 @@ export declare class LanguageServerClient<InitializationOptions = unknown> {
104
112
  protected notify<K extends keyof LSPNotifyMap>(method: K, params: LSPNotifyMap[K]): Promise<void>;
105
113
  protected processNotification(notification: Notification): void;
106
114
  }
115
+ /** Controls how document changes are sent to the language server. */
107
116
  export declare enum SynchronizationMethod {
117
+ /** Send the full document text on every change. */
108
118
  Full = "full",
119
+ /** Send only the changed ranges. More efficient for large documents. */
109
120
  Incremental = "incremental"
110
121
  }
111
122
  export declare class LanguageServerPlugin implements PluginValue {
@@ -181,16 +192,28 @@ export declare const languageServerPlugin: ViewPlugin<LanguageServerPlugin, {
181
192
  allowHTMLContent: boolean;
182
193
  synchronizationMethod: SynchronizationMethod;
183
194
  }>;
195
+ /** Base options shared by all language server configurations. */
184
196
  export interface LanguageServerBaseOptions {
197
+ /** Root URI of the workspace (e.g. `'file:///'`). */
185
198
  rootUri: string | null;
199
+ /** LSP workspace folders, if applicable. */
186
200
  workspaceFolders: LSP.WorkspaceFolder[] | null;
201
+ /** URI of the document being edited (e.g. `'file:///main.cpp'`). */
187
202
  documentUri: string;
203
+ /** Language identifier as defined by the LSP specification. */
188
204
  languageId: string;
189
205
  }
206
+ /** Options for creating a {@link LanguageServerClient}. */
190
207
  export interface LanguageServerClientOptions<InitializationOptions = unknown> extends LanguageServerBaseOptions {
208
+ /** The transport used to communicate with the language server. */
191
209
  transport: Transport;
210
+ /** Close the transport when the last plugin detaches. */
192
211
  autoClose?: boolean;
212
+ /** Server-specific initialization options. */
193
213
  initializationOptions?: InitializationOptions;
214
+ /** Locale for the LSP session (e.g. `'en'`). Sent in the `initialize` request. */
194
215
  locale?: string;
216
+ /** Called once after initialization with the server's capabilities. */
217
+ onCapabilities?: (capabilities: LSP.ServerCapabilities) => void;
195
218
  }
196
219
  export {};
package/dist/rename.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  import { StateField } from '@codemirror/state';
2
2
  import { EditorView } from '@codemirror/view';
3
+ /**
4
+ * Command: open a rename prompt for the symbol at the cursor.
5
+ *
6
+ * Uses `textDocument/prepareRename` to pre-fill the current name if supported
7
+ * by the server. Press Enter to confirm or Escape to cancel.
8
+ */
3
9
  export declare function renameSymbol(view: EditorView): boolean;
4
10
  export declare const renameExtension: () => StateField<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemirror-languageserver",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "Language Server Plugin for CodeMirror 6",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",