codemirror-languageserver 1.18.1 → 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 +201 -26
- package/dist/definition.d.ts +12 -0
- package/dist/formatting.d.ts +14 -0
- package/dist/highlight.d.ts +8 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +601 -66
- package/dist/jsonrpc.d.ts +42 -0
- package/dist/plugin.d.ts +59 -6
- package/dist/rename.d.ts +10 -0
- package/package.json +6 -5
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
*/
|
|
8
|
+
export interface Transport {
|
|
9
|
+
send(message: string): void;
|
|
10
|
+
onMessage(callback: (message: string) => void): void;
|
|
11
|
+
onClose(callback: () => void): void;
|
|
12
|
+
onError(callback: (error: Error) => void): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
/** A {@link Transport} that communicates over a browser-native WebSocket. */
|
|
16
|
+
export declare class WebSocketTransport implements Transport {
|
|
17
|
+
connection: WebSocket;
|
|
18
|
+
constructor(uri: string);
|
|
19
|
+
send(message: string): void;
|
|
20
|
+
onMessage(callback: (message: string) => void): void;
|
|
21
|
+
onClose(callback: () => void): void;
|
|
22
|
+
onError(callback: (error: Error) => void): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
export declare class JSONRPCClient {
|
|
26
|
+
private transport;
|
|
27
|
+
private nextId;
|
|
28
|
+
private pending;
|
|
29
|
+
private notificationHandlers;
|
|
30
|
+
private ready;
|
|
31
|
+
constructor(transport: Transport);
|
|
32
|
+
request(req: {
|
|
33
|
+
method: string;
|
|
34
|
+
params: any;
|
|
35
|
+
}, timeout: number): Promise<any>;
|
|
36
|
+
notify(notification: {
|
|
37
|
+
method: string;
|
|
38
|
+
params: any;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
onNotification(handler: (data: any) => void): void;
|
|
41
|
+
close(): void;
|
|
42
|
+
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EditorView, Tooltip, ViewPlugin } from '@codemirror/view';
|
|
2
|
+
import type { Transport } from './jsonrpc';
|
|
2
3
|
import { CompletionTriggerKind } from 'vscode-languageserver-protocol';
|
|
3
4
|
import type { CompletionContext, CompletionResult } from '@codemirror/autocomplete';
|
|
4
5
|
import type { PluginValue, ViewUpdate } from '@codemirror/view';
|
|
5
|
-
import { Transport } from '@open-rpc/client-js/build/transports/Transport';
|
|
6
6
|
import type { PublishDiagnosticsParams } from 'vscode-languageserver-protocol';
|
|
7
7
|
import type * as LSP from 'vscode-languageserver-protocol';
|
|
8
8
|
interface LSPRequestMap {
|
|
@@ -24,6 +24,26 @@ interface LSPRequestMap {
|
|
|
24
24
|
LSP.TypeDefinitionParams,
|
|
25
25
|
LSP.Location | LSP.Location[] | LSP.LocationLink[] | null
|
|
26
26
|
];
|
|
27
|
+
'textDocument/documentHighlight': [
|
|
28
|
+
LSP.DocumentHighlightParams,
|
|
29
|
+
LSP.DocumentHighlight[] | null
|
|
30
|
+
];
|
|
31
|
+
'textDocument/formatting': [
|
|
32
|
+
LSP.DocumentFormattingParams,
|
|
33
|
+
LSP.TextEdit[] | null
|
|
34
|
+
];
|
|
35
|
+
'textDocument/rangeFormatting': [
|
|
36
|
+
LSP.DocumentRangeFormattingParams,
|
|
37
|
+
LSP.TextEdit[] | null
|
|
38
|
+
];
|
|
39
|
+
'textDocument/prepareRename': [
|
|
40
|
+
LSP.PrepareRenameParams,
|
|
41
|
+
LSP.Range | {
|
|
42
|
+
range: LSP.Range;
|
|
43
|
+
placeholder: string;
|
|
44
|
+
} | null
|
|
45
|
+
];
|
|
46
|
+
'textDocument/rename': [LSP.RenameParams, LSP.WorkspaceEdit | null];
|
|
27
47
|
'completionItem/resolve': [LSP.CompletionItem, LSP.CompletionItem];
|
|
28
48
|
}
|
|
29
49
|
interface LSPNotifyMap {
|
|
@@ -47,15 +67,22 @@ interface LanguageServerClientLocationMethods {
|
|
|
47
67
|
textDocumentDeclaration(params: LSP.DeclarationParams): LSP.Location | LSP.Location[] | LSP.LocationLink[] | null;
|
|
48
68
|
textDocumentTypeDefinition(params: LSP.TypeDefinitionParams): LSP.Location | LSP.Location[] | LSP.LocationLink[] | null;
|
|
49
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
|
+
*/
|
|
50
76
|
export declare class LanguageServerClient<InitializationOptions = unknown> {
|
|
77
|
+
/** Whether the server has finished initializing. */
|
|
51
78
|
ready: boolean;
|
|
79
|
+
/** The server's capabilities, available after initialization. */
|
|
52
80
|
capabilities: LSP.ServerCapabilities<any>;
|
|
53
81
|
initializePromise: Promise<void>;
|
|
54
82
|
private rootUri;
|
|
55
83
|
private workspaceFolders;
|
|
56
84
|
private autoClose?;
|
|
57
85
|
private transport;
|
|
58
|
-
private requestManager;
|
|
59
86
|
private client;
|
|
60
87
|
private plugins;
|
|
61
88
|
private options;
|
|
@@ -63,32 +90,45 @@ export declare class LanguageServerClient<InitializationOptions = unknown> {
|
|
|
63
90
|
protected getInitializeParams(): LSP.InitializeParams;
|
|
64
91
|
initialize(): Promise<void>;
|
|
65
92
|
close(): void;
|
|
66
|
-
textDocumentDidOpen(params: LSP.DidOpenTextDocumentParams): Promise<
|
|
67
|
-
textDocumentDidChange(params: LSP.DidChangeTextDocumentParams): Promise<
|
|
93
|
+
textDocumentDidOpen(params: LSP.DidOpenTextDocumentParams): Promise<void>;
|
|
94
|
+
textDocumentDidChange(params: LSP.DidChangeTextDocumentParams): Promise<void>;
|
|
68
95
|
textDocumentHover(params: LSP.HoverParams): Promise<LSP.Hover>;
|
|
69
96
|
textDocumentCompletion(params: LSP.CompletionParams): Promise<LSP.CompletionList | LSP.CompletionItem[]>;
|
|
70
97
|
textDocumentDefinition(params: LSP.DefinitionParams): Promise<LSP.Location | LSP.Location[] | LSP.LocationLink[]>;
|
|
71
98
|
textDocumentDeclaration(params: LSP.DeclarationParams): Promise<LSP.Location | LSP.Location[] | LSP.LocationLink[]>;
|
|
72
99
|
textDocumentTypeDefinition(params: LSP.TypeDefinitionParams): Promise<LSP.Location | LSP.Location[] | LSP.LocationLink[]>;
|
|
100
|
+
textDocumentDocumentHighlight(params: LSP.DocumentHighlightParams): Promise<LSP.DocumentHighlight[]>;
|
|
101
|
+
textDocumentFormatting(params: LSP.DocumentFormattingParams): Promise<LSP.TextEdit[]>;
|
|
102
|
+
textDocumentRangeFormatting(params: LSP.DocumentRangeFormattingParams): Promise<LSP.TextEdit[]>;
|
|
103
|
+
textDocumentPrepareRename(params: LSP.PrepareRenameParams): Promise<LSP.Range | {
|
|
104
|
+
range: LSP.Range;
|
|
105
|
+
placeholder: string;
|
|
106
|
+
}>;
|
|
107
|
+
textDocumentRename(params: LSP.RenameParams): Promise<LSP.WorkspaceEdit>;
|
|
73
108
|
completionItemResolve(params: LSP.CompletionItem): Promise<LSP.CompletionItem>;
|
|
74
109
|
attachPlugin(plugin: LanguageServerPlugin): void;
|
|
75
110
|
detachPlugin(plugin: LanguageServerPlugin): void;
|
|
76
111
|
protected request<K extends keyof LSPRequestMap>(method: K, params: LSPRequestMap[K][0], timeout: number): Promise<LSPRequestMap[K][1]>;
|
|
77
|
-
protected notify<K extends keyof LSPNotifyMap>(method: K, params: LSPNotifyMap[K]): Promise<
|
|
112
|
+
protected notify<K extends keyof LSPNotifyMap>(method: K, params: LSPNotifyMap[K]): Promise<void>;
|
|
78
113
|
protected processNotification(notification: Notification): void;
|
|
79
114
|
}
|
|
115
|
+
/** Controls how document changes are sent to the language server. */
|
|
80
116
|
export declare enum SynchronizationMethod {
|
|
117
|
+
/** Send the full document text on every change. */
|
|
81
118
|
Full = "full",
|
|
119
|
+
/** Send only the changed ranges. More efficient for large documents. */
|
|
82
120
|
Incremental = "incremental"
|
|
83
121
|
}
|
|
84
122
|
export declare class LanguageServerPlugin implements PluginValue {
|
|
85
123
|
private view;
|
|
86
124
|
client: LanguageServerClient;
|
|
87
|
-
|
|
125
|
+
documentUri: string;
|
|
88
126
|
private languageId;
|
|
89
127
|
private documentVersion;
|
|
90
128
|
private allowHTMLContent;
|
|
91
129
|
private synchronizationMethod;
|
|
130
|
+
private changesTimeout;
|
|
131
|
+
private pendingChanges;
|
|
92
132
|
constructor(view: EditorView, { client, documentUri, languageId, allowHTMLContent, synchronizationMethod, }: {
|
|
93
133
|
client: LanguageServerClient;
|
|
94
134
|
documentUri: string;
|
|
@@ -152,15 +192,28 @@ export declare const languageServerPlugin: ViewPlugin<LanguageServerPlugin, {
|
|
|
152
192
|
allowHTMLContent: boolean;
|
|
153
193
|
synchronizationMethod: SynchronizationMethod;
|
|
154
194
|
}>;
|
|
195
|
+
/** Base options shared by all language server configurations. */
|
|
155
196
|
export interface LanguageServerBaseOptions {
|
|
197
|
+
/** Root URI of the workspace (e.g. `'file:///'`). */
|
|
156
198
|
rootUri: string | null;
|
|
199
|
+
/** LSP workspace folders, if applicable. */
|
|
157
200
|
workspaceFolders: LSP.WorkspaceFolder[] | null;
|
|
201
|
+
/** URI of the document being edited (e.g. `'file:///main.cpp'`). */
|
|
158
202
|
documentUri: string;
|
|
203
|
+
/** Language identifier as defined by the LSP specification. */
|
|
159
204
|
languageId: string;
|
|
160
205
|
}
|
|
206
|
+
/** Options for creating a {@link LanguageServerClient}. */
|
|
161
207
|
export interface LanguageServerClientOptions<InitializationOptions = unknown> extends LanguageServerBaseOptions {
|
|
208
|
+
/** The transport used to communicate with the language server. */
|
|
162
209
|
transport: Transport;
|
|
210
|
+
/** Close the transport when the last plugin detaches. */
|
|
163
211
|
autoClose?: boolean;
|
|
212
|
+
/** Server-specific initialization options. */
|
|
164
213
|
initializationOptions?: InitializationOptions;
|
|
214
|
+
/** Locale for the LSP session (e.g. `'en'`). Sent in the `initialize` request. */
|
|
215
|
+
locale?: string;
|
|
216
|
+
/** Called once after initialization with the server's capabilities. */
|
|
217
|
+
onCapabilities?: (capabilities: LSP.ServerCapabilities) => void;
|
|
165
218
|
}
|
|
166
219
|
export {};
|
package/dist/rename.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StateField } from '@codemirror/state';
|
|
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
|
+
*/
|
|
9
|
+
export declare function renameSymbol(view: EditorView): boolean;
|
|
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.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Language Server Plugin for CodeMirror 6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"typescript": "^5.9.2"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"marked": "^16.1.2",
|
|
44
|
+
"vscode-languageserver-protocol": "^3.17.5"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
43
47
|
"@codemirror/autocomplete": "^6.18.6",
|
|
44
48
|
"@codemirror/lint": "^6.8.5",
|
|
45
49
|
"@codemirror/state": "^6.5.2",
|
|
46
|
-
"@codemirror/view": "^6.38.1"
|
|
47
|
-
"@open-rpc/client-js": "^1.8.1",
|
|
48
|
-
"marked": "^16.1.2",
|
|
49
|
-
"vscode-languageserver-protocol": "^3.17.5"
|
|
50
|
+
"@codemirror/view": "^6.38.1"
|
|
50
51
|
},
|
|
51
52
|
"prettier": {
|
|
52
53
|
"tabWidth": 4,
|