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.
@@ -0,0 +1,407 @@
1
+ import { EditorView, Tooltip, ViewPlugin } from '@codemirror/view';
2
+ import { CompletionTriggerKind } from 'vscode-languageserver-protocol';
3
+ import type { CompletionContext, CompletionResult } from '@codemirror/autocomplete';
4
+ import type { PluginValue, ViewUpdate } from '@codemirror/view';
5
+ import { Transport } from '@open-rpc/client-js/build/transports/Transport';
6
+ import type { PublishDiagnosticsParams } from 'vscode-languageserver-protocol';
7
+ import type * as LSP from 'vscode-languageserver-protocol';
8
+ interface LSPRequestMap {
9
+ initialize: [LSP.InitializeParams, LSP.InitializeResult];
10
+ 'textDocument/hover': [LSP.HoverParams, LSP.Hover];
11
+ 'textDocument/completion': [
12
+ LSP.CompletionParams,
13
+ LSP.CompletionItem[] | LSP.CompletionList | null
14
+ ];
15
+ 'textDocument/definition': [
16
+ LSP.DefinitionParams,
17
+ LSP.Location | LSP.Location[] | LSP.LocationLink[] | null
18
+ ];
19
+ }
20
+ interface LSPNotifyMap {
21
+ initialized: LSP.InitializedParams;
22
+ 'textDocument/didChange': LSP.DidChangeTextDocumentParams;
23
+ 'textDocument/didOpen': LSP.DidOpenTextDocumentParams;
24
+ }
25
+ interface LSPEventMap {
26
+ 'textDocument/publishDiagnostics': LSP.PublishDiagnosticsParams;
27
+ }
28
+ type Notification = {
29
+ [key in keyof LSPEventMap]: {
30
+ jsonrpc: '2.0';
31
+ id?: null | undefined;
32
+ method: key;
33
+ params: LSPEventMap[key];
34
+ };
35
+ }[keyof LSPEventMap];
36
+ export declare class LanguageServerClient<InitializationOptions = unknown> {
37
+ ready: boolean;
38
+ capabilities: LSP.ServerCapabilities<any>;
39
+ initializePromise: Promise<void>;
40
+ private rootUri;
41
+ private workspaceFolders;
42
+ private autoClose?;
43
+ private transport;
44
+ private requestManager;
45
+ private client;
46
+ private plugins;
47
+ private options;
48
+ constructor(options: LanguageServerClientOptions<InitializationOptions>);
49
+ protected getInitializeParams(): LSP.InitializeParams;
50
+ initialize(): Promise<void>;
51
+ close(): void;
52
+ textDocumentDidOpen(params: LSP.DidOpenTextDocumentParams): Promise<LSP.DidOpenTextDocumentParams>;
53
+ textDocumentDidChange(params: LSP.DidChangeTextDocumentParams): Promise<LSP.DidChangeTextDocumentParams>;
54
+ textDocumentHover(params: LSP.HoverParams): Promise<LSP.Hover>;
55
+ textDocumentCompletion(params: LSP.CompletionParams): Promise<LSP.CompletionList | LSP.CompletionItem[]>;
56
+ textDocumentDefinition(params: LSP.DefinitionParams): Promise<LSP.Location | LSP.Location[] | LSP.LocationLink[]>;
57
+ attachPlugin(plugin: LanguageServerPlugin): void;
58
+ detachPlugin(plugin: LanguageServerPlugin): void;
59
+ protected request<K extends keyof LSPRequestMap>(method: K, params: LSPRequestMap[K][0], timeout: number): Promise<LSPRequestMap[K][1]>;
60
+ protected notify<K extends keyof LSPNotifyMap>(method: K, params: LSPNotifyMap[K]): Promise<LSPNotifyMap[K]>;
61
+ protected processNotification(notification: Notification): void;
62
+ }
63
+ declare class LanguageServerPlugin implements PluginValue {
64
+ private view;
65
+ private allowHTMLContent;
66
+ client: LanguageServerClient;
67
+ private documentUri;
68
+ private languageId;
69
+ private documentVersion;
70
+ private changesTimeout;
71
+ constructor(view: EditorView, allowHTMLContent: boolean);
72
+ update({ docChanged }: ViewUpdate): void;
73
+ destroy(): void;
74
+ initialize({ documentText }: {
75
+ documentText: string;
76
+ }): Promise<void>;
77
+ sendChange({ documentText }: {
78
+ documentText: string;
79
+ }): Promise<void>;
80
+ requestDiagnostics(view: EditorView): void;
81
+ requestHoverTooltip(view: EditorView, { line, character }: {
82
+ line: number;
83
+ character: number;
84
+ }): Promise<Tooltip | null>;
85
+ requestCompletion(context: CompletionContext, { line, character }: {
86
+ line: number;
87
+ character: number;
88
+ }, { triggerKind, triggerCharacter, }: {
89
+ triggerKind: CompletionTriggerKind;
90
+ triggerCharacter: string | undefined;
91
+ }): Promise<CompletionResult | null>;
92
+ requestDefinition(view: EditorView, { line, character }: {
93
+ line: number;
94
+ character: number;
95
+ }): Promise<{
96
+ uri: string;
97
+ range: LSP.Range;
98
+ }>;
99
+ processNotification(notification: Notification): void;
100
+ processDiagnostics(params: PublishDiagnosticsParams): void;
101
+ }
102
+ export declare const languageServerPlugin: ViewPlugin<LanguageServerPlugin, boolean>;
103
+ interface LanguageServerBaseOptions {
104
+ rootUri: string | null;
105
+ workspaceFolders: LSP.WorkspaceFolder[] | null;
106
+ documentUri: string;
107
+ languageId: string;
108
+ }
109
+ interface LanguageServerClientOptions<InitializationOptions = unknown> extends LanguageServerBaseOptions {
110
+ transport: Transport;
111
+ autoClose?: boolean;
112
+ initializationOptions?: InitializationOptions;
113
+ }
114
+ interface LanguageServerOptions<InitializationOptions = unknown> extends LanguageServerClientOptions<InitializationOptions> {
115
+ client?: LanguageServerClient<InitializationOptions>;
116
+ allowHTMLContent?: boolean;
117
+ }
118
+ interface LanguageServerWebsocketOptions<InitializationOptions = unknown> extends LanguageServerBaseOptions {
119
+ serverUri: `ws://${string}` | `wss://${string}`;
120
+ initializationOptions?: InitializationOptions;
121
+ }
122
+ export declare function languageServer<InitializationOptions = unknown>(options: LanguageServerWebsocketOptions<InitializationOptions>): ({
123
+ extension: import("@codemirror/state").Extension;
124
+ } | readonly import("@codemirror/state").Extension[])[];
125
+ export declare function languageServerWithTransport<InitializationOptions = unknown>(options: LanguageServerOptions<InitializationOptions>): ({
126
+ extension: import("@codemirror/state").Extension;
127
+ } | readonly import("@codemirror/state").Extension[])[];
128
+ /**
129
+ * Initialization options for Pyright language server
130
+ * @see https://github.com/microsoft/pyright/blob/main/docs/settings.md
131
+ */
132
+ export interface PyrightInitializationOptions {
133
+ python?: {
134
+ pythonPath?: string;
135
+ venvPath?: string;
136
+ analysis?: {
137
+ autoSearchPaths?: boolean;
138
+ extraPaths?: string[];
139
+ diagnosticMode?: 'workspace' | 'openFilesOnly';
140
+ stubPath?: string;
141
+ typeshedPaths?: string[];
142
+ useLibraryCodeForTypes?: boolean;
143
+ typeCheckingMode?: 'off' | 'basic' | 'strict';
144
+ autoImportCompletions?: boolean;
145
+ indexing?: boolean;
146
+ };
147
+ };
148
+ reportMissingImports?: boolean;
149
+ reportMissingTypeStubs?: boolean;
150
+ reportMissingModuleSource?: boolean;
151
+ reportInvalidTypeVarUse?: boolean;
152
+ reportOptionalSubscript?: boolean;
153
+ reportOptionalMemberAccess?: boolean;
154
+ reportOptionalCall?: boolean;
155
+ reportOptionalIterable?: boolean;
156
+ reportOptionalContextManager?: boolean;
157
+ reportOptionalOperand?: boolean;
158
+ reportTypedDictNotRequiredAccess?: boolean;
159
+ reportPrivateImportUsage?: boolean;
160
+ reportConstantRedefinition?: boolean;
161
+ reportIncompatibleMethodOverride?: boolean;
162
+ reportIncompatibleVariableOverride?: boolean;
163
+ reportInconsistentConstructor?: boolean;
164
+ }
165
+ /**
166
+ * Initialization options for Rust Analyzer language server
167
+ * @see https://rust-analyzer.github.io/manual.html#configuration
168
+ */
169
+ export interface RustAnalyzerInitializationOptions {
170
+ cargo?: {
171
+ buildScripts?: {
172
+ enable?: boolean;
173
+ invocationStrategy?: 'per_workspace' | 'once';
174
+ invocationLocation?: 'workspace' | 'root';
175
+ };
176
+ allTargets?: boolean;
177
+ noDefaultFeatures?: boolean;
178
+ allFeatures?: boolean;
179
+ features?: string[];
180
+ target?: string;
181
+ runBuildScripts?: boolean;
182
+ useRustcWrapperForBuildScripts?: boolean;
183
+ };
184
+ procMacro?: {
185
+ enable?: boolean;
186
+ ignored?: Record<string, string[]>;
187
+ server?: string;
188
+ attributes?: {
189
+ enable?: boolean;
190
+ };
191
+ };
192
+ diagnostics?: {
193
+ enable?: boolean;
194
+ disabled?: string[];
195
+ warningsAsHint?: string[];
196
+ warningsAsInfo?: string[];
197
+ remapPrefix?: Record<string, string>;
198
+ experimental?: {
199
+ enable?: boolean;
200
+ };
201
+ };
202
+ completion?: {
203
+ addCallArgumentSnippets?: boolean;
204
+ addCallParenthesis?: boolean;
205
+ postfix?: {
206
+ enable?: boolean;
207
+ };
208
+ autoimport?: {
209
+ enable?: boolean;
210
+ };
211
+ privateEditable?: {
212
+ enable?: boolean;
213
+ };
214
+ };
215
+ assist?: {
216
+ importGranularity?: 'preserve' | 'crate' | 'module' | 'item';
217
+ importEnforceGranularity?: boolean;
218
+ importPrefix?: 'plain' | 'by_self' | 'by_crate';
219
+ allowMergingIntoGlobImports?: boolean;
220
+ };
221
+ callInfo?: {
222
+ full?: boolean;
223
+ };
224
+ lens?: {
225
+ enable?: boolean;
226
+ run?: boolean;
227
+ debug?: boolean;
228
+ implementations?: boolean;
229
+ refs?: boolean;
230
+ methodReferences?: boolean;
231
+ references?: boolean;
232
+ enumVariantReferences?: boolean;
233
+ };
234
+ hover?: {
235
+ documentation?: boolean;
236
+ keywords?: boolean;
237
+ linksInHover?: boolean;
238
+ memoryLayout?: {
239
+ enable?: boolean;
240
+ };
241
+ };
242
+ workspace?: {
243
+ symbol?: {
244
+ search?: {
245
+ scope?: 'workspace' | 'workspace_and_dependencies';
246
+ kind?: 'only_types' | 'all_symbols';
247
+ };
248
+ };
249
+ };
250
+ }
251
+ /**
252
+ * Initialization options for TypeScript/JavaScript language server
253
+ * @see https://github.com/typescript-language-server/typescript-language-server
254
+ */
255
+ export interface TypeScriptInitializationOptions {
256
+ hostInfo?: string;
257
+ npmLocation?: string;
258
+ globalPlugins?: string[];
259
+ pluginProbeLocations?: string[];
260
+ preferences?: {
261
+ includePackageJsonAutoImports?: 'auto' | 'on' | 'off';
262
+ providePrefixAndSuffixTextForRename?: boolean;
263
+ allowRenameOfImportPath?: boolean;
264
+ includeAutomaticOptionalChainCompletions?: boolean;
265
+ includeCompletionsForModuleExports?: boolean;
266
+ includeCompletionsForImportStatements?: boolean;
267
+ includeCompletionsWithSnippetText?: boolean;
268
+ includeCompletionsWithInsertText?: boolean;
269
+ allowIncompleteCompletions?: boolean;
270
+ importModuleSpecifier?: 'shortest' | 'relative' | 'absolute' | 'auto';
271
+ importModuleSpecifierEnding?: 'minimal' | 'index' | 'js';
272
+ allowTextChangesInNewFiles?: boolean;
273
+ lazyConfiguredProjectsFromExternalProject?: boolean;
274
+ providePrefixAndSuffixTextForQuickInfo?: boolean;
275
+ includeInlayParameterNameHints?: 'none' | 'literals' | 'all';
276
+ includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
277
+ includeInlayFunctionParameterTypeHints?: boolean;
278
+ includeInlayVariableTypeHints?: boolean;
279
+ includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
280
+ includeInlayPropertyDeclarationTypeHints?: boolean;
281
+ includeInlayFunctionLikeReturnTypeHints?: boolean;
282
+ includeInlayEnumMemberValueHints?: boolean;
283
+ };
284
+ locale?: string;
285
+ maxTsServerMemory?: number;
286
+ tsserver?: {
287
+ logLevel?: 'off' | 'terse' | 'normal' | 'requestTime' | 'verbose';
288
+ logVerbosity?: 'off' | 'terse' | 'normal' | 'requestTime' | 'verbose';
289
+ trace?: 'off' | 'messages' | 'verbose';
290
+ useSeparateSyntaxServer?: boolean;
291
+ enableTracing?: boolean;
292
+ path?: string;
293
+ };
294
+ }
295
+ /**
296
+ * Initialization options for ESLint language server
297
+ * @see https://github.com/Microsoft/vscode-eslint
298
+ */
299
+ export interface ESLintInitializationOptions {
300
+ packageManager?: 'npm' | 'yarn' | 'pnpm';
301
+ nodePath?: string;
302
+ options?: Record<string, any>;
303
+ rules?: Record<string, any>;
304
+ rulesCustomizations?: Array<{
305
+ rule: string;
306
+ severity: 'downgrade' | 'upgrade' | 'info' | 'warn' | 'error' | 'off';
307
+ }>;
308
+ run?: 'onType' | 'onSave';
309
+ problems?: {
310
+ shortenToSingleLine?: boolean;
311
+ };
312
+ codeAction?: {
313
+ disableRuleComment?: {
314
+ enable?: boolean;
315
+ location?: 'separateLine' | 'sameLine';
316
+ };
317
+ showDocumentation?: {
318
+ enable?: boolean;
319
+ };
320
+ };
321
+ codeActionOnSave?: {
322
+ enable?: boolean;
323
+ mode?: 'all' | 'problems';
324
+ };
325
+ format?: {
326
+ enable?: boolean;
327
+ };
328
+ quiet?: boolean;
329
+ onIgnoredFiles?: 'off' | 'warn';
330
+ useESLintClass?: boolean;
331
+ experimental?: {
332
+ useFlatConfig?: boolean;
333
+ };
334
+ workingDirectory?: {
335
+ mode?: 'auto' | 'location';
336
+ };
337
+ }
338
+ /**
339
+ * Initialization options for Clangd language server
340
+ * @see https://clangd.llvm.org/config
341
+ */
342
+ export interface ClangdInitializationOptions {
343
+ compilationDatabasePath?: string;
344
+ compilationDatabaseChanges?: Record<string, any>;
345
+ fallbackFlags?: string[];
346
+ clangdFileStatus?: boolean;
347
+ utf8?: boolean;
348
+ offsetEncoding?: ('utf-8' | 'utf-16' | 'utf-32')[];
349
+ index?: {
350
+ background?: 'Build' | 'Skip';
351
+ threads?: number;
352
+ };
353
+ completion?: {
354
+ detailedLabel?: boolean;
355
+ allScopes?: boolean;
356
+ };
357
+ hover?: {
358
+ showAKA?: boolean;
359
+ };
360
+ inlayHints?: {
361
+ enabled?: boolean;
362
+ parameterNames?: boolean;
363
+ deducedTypes?: boolean;
364
+ designators?: boolean;
365
+ };
366
+ semanticHighlighting?: boolean;
367
+ diagnostics?: {
368
+ unusedIncludes?: 'None' | 'Strict';
369
+ missingIncludes?: 'None' | 'Strict';
370
+ clangTidy?: boolean;
371
+ suppressAll?: boolean;
372
+ };
373
+ }
374
+ /**
375
+ * Initialization options for Gopls (Go language server)
376
+ * @see https://github.com/golang/tools/blob/master/gopls/doc/settings.md
377
+ */
378
+ export interface GoplsInitializationOptions {
379
+ buildFlags?: string[];
380
+ env?: Record<string, string>;
381
+ directoryFilters?: string[];
382
+ templateExtensions?: string[];
383
+ memoryMode?: 'DegradeClosed' | 'Normal';
384
+ gofumpt?: boolean;
385
+ staticcheck?: boolean;
386
+ analyses?: Record<string, boolean>;
387
+ codelenses?: Record<string, boolean>;
388
+ usePlaceholders?: boolean;
389
+ completionBudget?: string;
390
+ diagnosticsDelay?: string;
391
+ experimentalPostfixCompletions?: boolean;
392
+ experimentalWorkspaceModule?: boolean;
393
+ experimentalTemplateSupport?: boolean;
394
+ semanticTokens?: boolean;
395
+ noSemanticString?: boolean;
396
+ noSemanticNumber?: boolean;
397
+ expandWorkspaceToModule?: boolean;
398
+ experimentalUseInvalidMetadata?: boolean;
399
+ hoverKind?: 'FullDocumentation' | 'NoDocumentation' | 'SingleLine' | 'Structured' | 'SynopsisDocumentation';
400
+ linkTarget?: string;
401
+ linksInHover?: boolean;
402
+ importShortcut?: 'Both' | 'Definition' | 'Link';
403
+ symbolMatcher?: 'CaseInsensitive' | 'CaseSensitive' | 'FastFuzzy' | 'Fuzzy';
404
+ symbolStyle?: 'Dynamic' | 'Full' | 'Package';
405
+ verboseOutput?: boolean;
406
+ }
407
+ export {};
package/dist/pos.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { Text } from '@codemirror/state';
2
+ export declare function posToOffset(doc: Text, pos: {
3
+ line: number;
4
+ character: number;
5
+ }): number;
6
+ export declare function offsetToPos(doc: Text, offset: number): {
7
+ character: number;
8
+ line: number;
9
+ };
package/package.json CHANGED
@@ -1,48 +1,55 @@
1
1
  {
2
- "name": "codemirror-languageserver",
3
- "version": "1.13.0",
4
- "description": "Language Server Plugin for CodeMirror 6",
5
- "main": "dist/index.js",
6
- "type": "module",
7
- "scripts": {
8
- "prepare": "rollup -c rollup.config.js"
9
- },
10
- "author": {
11
- "name": "Mahmud Ridwan",
12
- "email": "m@hjr265.me",
13
- "url": "https://hjr265.me"
14
- },
15
- "homepage": "https://github.com/FurqanSoftware/codemirror-languageserver",
16
- "bugs": {
17
- "url": "https://github.com/FurqanSoftware/codemirror-languageserver/issues"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/FurqanSoftware/codemirror-languageserver.git"
22
- },
23
- "license": "BSD-3-Clause",
24
- "devDependencies": {
25
- "@babel/core": "^7.28.0",
26
- "@babel/preset-env": "^7.28.0",
27
- "@rollup/plugin-babel": "^6.0.4",
28
- "@rollup/plugin-typescript": "^12.1.4",
29
- "prettier": "^3.6.2",
30
- "rollup": "^4.46.2",
31
- "tslib": "^2.8.1",
32
- "tslint": "^6.1.3",
33
- "typescript": "^5.9.2"
34
- },
35
- "dependencies": {
36
- "@codemirror/autocomplete": "^6.18.6",
37
- "@codemirror/lint": "^6.8.5",
38
- "@codemirror/state": "^6.5.2",
39
- "@codemirror/view": "^6.38.1",
40
- "@open-rpc/client-js": "^1.8.1",
41
- "marked": "^16.1.2",
42
- "vscode-languageserver-protocol": "^3.17.5"
43
- },
44
- "prettier": {
45
- "tabWidth": 4,
46
- "singleQuote": true
47
- }
2
+ "name": "codemirror-languageserver",
3
+ "version": "1.15.0",
4
+ "description": "Language Server Plugin for CodeMirror 6",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "prepare": "rollup -c rollup.config.js"
9
+ },
10
+ "author": {
11
+ "name": "Mahmud Ridwan",
12
+ "email": "m@hjr265.me",
13
+ "url": "https://hjr265.me"
14
+ },
15
+ "homepage": "https://github.com/FurqanSoftware/codemirror-languageserver",
16
+ "bugs": {
17
+ "url": "https://github.com/FurqanSoftware/codemirror-languageserver/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/FurqanSoftware/codemirror-languageserver.git"
22
+ },
23
+ "license": "BSD-3-Clause",
24
+ "devDependencies": {
25
+ "@babel/core": "^7.28.0",
26
+ "@babel/preset-env": "^7.28.0",
27
+ "@codemirror/commands": "^6.8.1",
28
+ "@codemirror/lang-cpp": "^6.0.3",
29
+ "@codemirror/search": "^6.5.11",
30
+ "@rollup/plugin-babel": "^6.0.4",
31
+ "@rollup/plugin-commonjs": "^28.0.6",
32
+ "@rollup/plugin-node-resolve": "^16.0.1",
33
+ "@rollup/plugin-typescript": "^12.1.4",
34
+ "prettier": "^3.6.2",
35
+ "rollup": "^4.46.2",
36
+ "rollup-plugin-node-polyfills": "^0.2.1",
37
+ "rollup-plugin-serve": "^3.0.0",
38
+ "tslib": "^2.8.1",
39
+ "tslint": "^6.1.3",
40
+ "typescript": "^5.9.2"
41
+ },
42
+ "dependencies": {
43
+ "@codemirror/autocomplete": "^6.18.6",
44
+ "@codemirror/lint": "^6.8.5",
45
+ "@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
+ },
51
+ "prettier": {
52
+ "tabWidth": 4,
53
+ "singleQuote": true
54
+ }
48
55
  }
@@ -0,0 +1,30 @@
1
+ import babel from '@rollup/plugin-babel';
2
+ import typescript from '@rollup/plugin-typescript';
3
+ import serve from 'rollup-plugin-serve';
4
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
5
+ import commonjs from '@rollup/plugin-commonjs';
6
+ import nodePolyfills from 'rollup-plugin-node-polyfills';
7
+
8
+ export default {
9
+ input: 'demo/demo.js',
10
+ output: {
11
+ dir: 'demo/dist',
12
+ format: 'es',
13
+ intro: 'const global = window;',
14
+ },
15
+ plugins: [
16
+ typescript({
17
+ declaration: false,
18
+ }),
19
+ babel({
20
+ babelHelpers: 'bundled',
21
+ }),
22
+ nodeResolve({
23
+ browser: true,
24
+ preferBuiltins: true,
25
+ }),
26
+ commonjs(),
27
+ nodePolyfills(),
28
+ serve('./demo'),
29
+ ],
30
+ };