@codemirror/lsp-client
Advanced tools
| import type * as lsp from "vscode-languageserver-protocol" | ||
| import {setDiagnostics} from "@codemirror/lint" | ||
| import {LSPPlugin} from "./plugin" | ||
| import {LSPClientExtension} from "./client" | ||
| function toSeverity(sev: lsp.DiagnosticSeverity) { | ||
| return sev == 1 ? "error" : sev == 2 ? "warning" : sev == 3 ? "info" : "hint" | ||
| } | ||
| export function serverDiagnostics(): LSPClientExtension { | ||
| return { | ||
| clientCapabilities: {textDocument: {publishDiagnostics: {versionSupport: true}}}, | ||
| notificationHandlers: { | ||
| "textDocument/publishDiagnostics": (client, params: lsp.PublishDiagnosticsParams) => { | ||
| let file = client.workspace.getFile(params.uri) | ||
| if (!file || params.version != null && params.version != file.version) return false | ||
| const view = file.getView(), plugin = view && LSPPlugin.get(view) | ||
| if (!view || !plugin) return false | ||
| view.dispatch(setDiagnostics(view.state, params.diagnostics.map(item => ({ | ||
| from: plugin.unsyncedChanges.mapPos(plugin.fromPosition(item.range.start, plugin.syncedDoc)), | ||
| to: plugin.unsyncedChanges.mapPos(plugin.fromPosition(item.range.end, plugin.syncedDoc)), | ||
| severity: toSeverity(item.severity ?? 1), | ||
| message: item.message, | ||
| })))) | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| } |
+12
-0
@@ -0,1 +1,13 @@ | ||
| ## 6.1.0 (2025-08-23) | ||
| ### New features | ||
| `LSPClient` now accepts an array of extensions directly in its configuration. These can also add behavior (client capabilities and notification handlers) to the client itself. | ||
| The new `serverDiagnostics` extension makes the client receive diagnostics from the server, and show them via the CodeMirror linter. | ||
| The new `languageServerExtensions` function provides an extension bundle interface, that works for client extensions as well as editor extensions. | ||
| `LSPClient` now has a `plugin` method for conveniently creating an editor extension. `LSPPlugin.create` is deprecated in favor of this method. | ||
| ## 6.0.1 (2025-08-05) | ||
@@ -2,0 +14,0 @@ |
+81
-17
@@ -238,4 +238,42 @@ import * as lsp from 'vscode-languageserver-protocol'; | ||
| unhandledNotification?: (client: LSPClient, method: string, params: any) => void; | ||
| /** | ||
| Provide a set of extensions, which may be plain CodeMirror | ||
| extensions, or objects containing additional client capabilities | ||
| or notification handlers. Any CodeMirror extensions provided | ||
| here will be included in the extension returned by | ||
| [`LSPPlugin.create`](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin^create). | ||
| */ | ||
| extensions?: readonly (Extension | LSPClientExtension)[]; | ||
| }; | ||
| /** | ||
| Objects of this type can be included in the | ||
| [`extensions`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions) option to | ||
| `LSPClient` to modularly configure client capabilities or | ||
| notification handlers. | ||
| */ | ||
| type LSPClientExtension = { | ||
| /** | ||
| Extra [client | ||
| capabilities](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities) | ||
| to send to the server when initializing. The object provided | ||
| here will be merged with the capabilities the client provides by | ||
| default. | ||
| */ | ||
| clientCapabilities?: Record<string, any>; | ||
| /** | ||
| Additional [notification | ||
| handlers](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.notificationHandlers). | ||
| These will be tried after notification handlers defined directly | ||
| in the config object, and then in order of appearance in the | ||
| [`extensions`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions) array. | ||
| */ | ||
| notificationHandlers?: { | ||
| [method: string]: (client: LSPClient, params: any) => boolean; | ||
| }; | ||
| /** | ||
| An optional CodeMirror extension to include. | ||
| */ | ||
| editorExtension?: Extension; | ||
| }; | ||
| /** | ||
| An LSP client manages a connection to a language server. It should | ||
@@ -289,2 +327,20 @@ be explicitly [connected](https://codemirror.net/6/docs/ref/#lsp-client.LSPClient.connect) before | ||
| /** | ||
| Create a plugin for this client, to add to an editor | ||
| configuration. This extension is necessary to use LSP-related | ||
| functionality exported by this package. The returned extension | ||
| will include the editor | ||
| extensions included in this client's | ||
| [configuration](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions). | ||
| Creating an editor with this plugin will cause | ||
| [`openFile`](https://codemirror.net/6/docs/ref/#lsp-client.Workspace.openFile) to be called on the | ||
| workspace. | ||
| By default, the language ID given to the server for this file is | ||
| derived from the editor's language configuration via | ||
| [`Language.name`](https://codemirror.net/6/docs/ref/#language.Language.name). You can pass in | ||
| a specific ID as a third parameter. | ||
| */ | ||
| plugin(fileURI: string, languageID?: string): Extension; | ||
| /** | ||
| Send a `textDocument/didOpen` notification to the server. | ||
@@ -380,2 +436,6 @@ */ | ||
| /** | ||
| The version of the document that was synchronized to the server. | ||
| */ | ||
| syncedDoc: Text; | ||
| /** | ||
| The changes accumulated in this editor that have not been sent | ||
@@ -396,13 +456,4 @@ to the server yet. | ||
| /** | ||
| Create an editor extension that connects that editor to the | ||
| given LSP client. This extension is necessary to use LSP-related | ||
| functionality exported by this package. Creating an editor with | ||
| this plugin will cause | ||
| [`openFile`](https://codemirror.net/6/docs/ref/#lsp-client.Workspace.openFile) to be called on the | ||
| workspace. | ||
| By default, the language ID given to the server for this file is | ||
| derived from the editor's language configuration via | ||
| [`Language.name`](https://codemirror.net/6/docs/ref/#language.Language.name). You can pass in | ||
| a specific ID as a third parameter. | ||
| Deprecated. Use | ||
| [`LSPClient.plugin`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClient.plugin) instead. | ||
| */ | ||
@@ -549,12 +600,25 @@ static create(client: LSPClient, fileURI: string, languageID?: string): Extension; | ||
| declare function serverDiagnostics(): LSPClientExtension; | ||
| /** | ||
| Returns an extension that enables the [LSP | ||
| plugin](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin) and all other features provided by | ||
| this package. You can also pick and choose individual extensions | ||
| from the exports. In that case, make sure to also include | ||
| [`LSPPlugin.create`](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin^create) in your | ||
| extensions, or the others will not work. | ||
| plugin](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin) as well as LSP based | ||
| autocompletion, hover tooltips, and signature help, along with the | ||
| keymaps for reformatting, renaming symbols, jumping to definition, | ||
| and finding references. | ||
| This function is deprecated. Prefer to directly use | ||
| [`LSPPlugin.create`](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin^create) and either add | ||
| the extensions you need directly, or configure them in the client | ||
| via [`languageServerExtensions`](https://codemirror.net/6/docs/ref/#lsp-client.languageServerExtensions). | ||
| */ | ||
| declare function languageServerSupport(client: LSPClient, uri: string, languageID?: string): Extension; | ||
| /** | ||
| This function bundles all the extensions defined in this package, | ||
| in a way that can be passed to the | ||
| [`extensions`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions) option to | ||
| `LSPClient`. | ||
| */ | ||
| declare function languageServerExtensions(): readonly (Extension | LSPClientExtension)[]; | ||
| export { LSPClient, type LSPClientConfig, LSPPlugin, type Transport, Workspace, type WorkspaceFile, WorkspaceMapping, closeReferencePanel, findReferences, findReferencesKeymap, formatDocument, formatKeymap, hoverTooltips, jumpToDeclaration, jumpToDefinition, jumpToDefinitionKeymap, jumpToImplementation, jumpToTypeDefinition, languageServerSupport, nextSignature, prevSignature, renameKeymap, renameSymbol, serverCompletion, serverCompletionSource, showSignatureHelp, signatureHelp, signatureKeymap }; | ||
| export { LSPClient, type LSPClientConfig, type LSPClientExtension, LSPPlugin, type Transport, Workspace, type WorkspaceFile, WorkspaceMapping, closeReferencePanel, findReferences, findReferencesKeymap, formatDocument, formatKeymap, hoverTooltips, jumpToDeclaration, jumpToDefinition, jumpToDefinitionKeymap, jumpToImplementation, jumpToTypeDefinition, languageServerExtensions, languageServerSupport, nextSignature, prevSignature, renameKeymap, renameSymbol, serverCompletion, serverCompletionSource, serverDiagnostics, showSignatureHelp, signatureHelp, signatureKeymap }; |
+81
-17
@@ -238,4 +238,42 @@ import * as lsp from 'vscode-languageserver-protocol'; | ||
| unhandledNotification?: (client: LSPClient, method: string, params: any) => void; | ||
| /** | ||
| Provide a set of extensions, which may be plain CodeMirror | ||
| extensions, or objects containing additional client capabilities | ||
| or notification handlers. Any CodeMirror extensions provided | ||
| here will be included in the extension returned by | ||
| [`LSPPlugin.create`](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin^create). | ||
| */ | ||
| extensions?: readonly (Extension | LSPClientExtension)[]; | ||
| }; | ||
| /** | ||
| Objects of this type can be included in the | ||
| [`extensions`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions) option to | ||
| `LSPClient` to modularly configure client capabilities or | ||
| notification handlers. | ||
| */ | ||
| type LSPClientExtension = { | ||
| /** | ||
| Extra [client | ||
| capabilities](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities) | ||
| to send to the server when initializing. The object provided | ||
| here will be merged with the capabilities the client provides by | ||
| default. | ||
| */ | ||
| clientCapabilities?: Record<string, any>; | ||
| /** | ||
| Additional [notification | ||
| handlers](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.notificationHandlers). | ||
| These will be tried after notification handlers defined directly | ||
| in the config object, and then in order of appearance in the | ||
| [`extensions`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions) array. | ||
| */ | ||
| notificationHandlers?: { | ||
| [method: string]: (client: LSPClient, params: any) => boolean; | ||
| }; | ||
| /** | ||
| An optional CodeMirror extension to include. | ||
| */ | ||
| editorExtension?: Extension; | ||
| }; | ||
| /** | ||
| An LSP client manages a connection to a language server. It should | ||
@@ -289,2 +327,20 @@ be explicitly [connected](https://codemirror.net/6/docs/ref/#lsp-client.LSPClient.connect) before | ||
| /** | ||
| Create a plugin for this client, to add to an editor | ||
| configuration. This extension is necessary to use LSP-related | ||
| functionality exported by this package. The returned extension | ||
| will include the editor | ||
| extensions included in this client's | ||
| [configuration](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions). | ||
| Creating an editor with this plugin will cause | ||
| [`openFile`](https://codemirror.net/6/docs/ref/#lsp-client.Workspace.openFile) to be called on the | ||
| workspace. | ||
| By default, the language ID given to the server for this file is | ||
| derived from the editor's language configuration via | ||
| [`Language.name`](https://codemirror.net/6/docs/ref/#language.Language.name). You can pass in | ||
| a specific ID as a third parameter. | ||
| */ | ||
| plugin(fileURI: string, languageID?: string): Extension; | ||
| /** | ||
| Send a `textDocument/didOpen` notification to the server. | ||
@@ -380,2 +436,6 @@ */ | ||
| /** | ||
| The version of the document that was synchronized to the server. | ||
| */ | ||
| syncedDoc: Text; | ||
| /** | ||
| The changes accumulated in this editor that have not been sent | ||
@@ -396,13 +456,4 @@ to the server yet. | ||
| /** | ||
| Create an editor extension that connects that editor to the | ||
| given LSP client. This extension is necessary to use LSP-related | ||
| functionality exported by this package. Creating an editor with | ||
| this plugin will cause | ||
| [`openFile`](https://codemirror.net/6/docs/ref/#lsp-client.Workspace.openFile) to be called on the | ||
| workspace. | ||
| By default, the language ID given to the server for this file is | ||
| derived from the editor's language configuration via | ||
| [`Language.name`](https://codemirror.net/6/docs/ref/#language.Language.name). You can pass in | ||
| a specific ID as a third parameter. | ||
| Deprecated. Use | ||
| [`LSPClient.plugin`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClient.plugin) instead. | ||
| */ | ||
@@ -549,12 +600,25 @@ static create(client: LSPClient, fileURI: string, languageID?: string): Extension; | ||
| declare function serverDiagnostics(): LSPClientExtension; | ||
| /** | ||
| Returns an extension that enables the [LSP | ||
| plugin](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin) and all other features provided by | ||
| this package. You can also pick and choose individual extensions | ||
| from the exports. In that case, make sure to also include | ||
| [`LSPPlugin.create`](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin^create) in your | ||
| extensions, or the others will not work. | ||
| plugin](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin) as well as LSP based | ||
| autocompletion, hover tooltips, and signature help, along with the | ||
| keymaps for reformatting, renaming symbols, jumping to definition, | ||
| and finding references. | ||
| This function is deprecated. Prefer to directly use | ||
| [`LSPPlugin.create`](https://codemirror.net/6/docs/ref/#lsp-client.LSPPlugin^create) and either add | ||
| the extensions you need directly, or configure them in the client | ||
| via [`languageServerExtensions`](https://codemirror.net/6/docs/ref/#lsp-client.languageServerExtensions). | ||
| */ | ||
| declare function languageServerSupport(client: LSPClient, uri: string, languageID?: string): Extension; | ||
| /** | ||
| This function bundles all the extensions defined in this package, | ||
| in a way that can be passed to the | ||
| [`extensions`](https://codemirror.net/6/docs/ref/#lsp-client.LSPClientConfig.extensions) option to | ||
| `LSPClient`. | ||
| */ | ||
| declare function languageServerExtensions(): readonly (Extension | LSPClientExtension)[]; | ||
| export { LSPClient, type LSPClientConfig, LSPPlugin, type Transport, Workspace, type WorkspaceFile, WorkspaceMapping, closeReferencePanel, findReferences, findReferencesKeymap, formatDocument, formatKeymap, hoverTooltips, jumpToDeclaration, jumpToDefinition, jumpToDefinitionKeymap, jumpToImplementation, jumpToTypeDefinition, languageServerSupport, nextSignature, prevSignature, renameKeymap, renameSymbol, serverCompletion, serverCompletionSource, showSignatureHelp, signatureHelp, signatureKeymap }; | ||
| export { LSPClient, type LSPClientConfig, type LSPClientExtension, LSPPlugin, type Transport, Workspace, type WorkspaceFile, WorkspaceMapping, closeReferencePanel, findReferences, findReferencesKeymap, formatDocument, formatKeymap, hoverTooltips, jumpToDeclaration, jumpToDefinition, jumpToDefinitionKeymap, jumpToImplementation, jumpToTypeDefinition, languageServerExtensions, languageServerSupport, nextSignature, prevSignature, renameKeymap, renameSymbol, serverCompletion, serverCompletionSource, serverDiagnostics, showSignatureHelp, signatureHelp, signatureKeymap }; |
+1
-1
| { | ||
| "name": "@codemirror/lsp-client", | ||
| "version": "6.0.1", | ||
| "version": "6.1.0", | ||
| "description": "Language server protocol client for CodeMirror", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+3
-3
@@ -38,3 +38,3 @@ # @codemirror/lsp-client [](https://www.npmjs.org/package/@codemirror/lsp-client) | ||
| ```javascript | ||
| import {Transport, LSPClient, languageServerSupport} from "@codemirror/lsp-client" | ||
| import {Transport, LSPClient, languageServerExtensions} from "@codemirror/lsp-client" | ||
| import {basicSetup, EditorView} from "codemirror" | ||
@@ -57,3 +57,3 @@ import {typescriptLanguage} from "@codemirror/lang-javascript" | ||
| let transport = await simpleWebSocketTransport("ws://host:port") | ||
| let client = new LSPClient().connect(transport) | ||
| let client = new LSPClient({extensions: languageServerExtensions()}).connect(transport) | ||
@@ -64,3 +64,3 @@ new EditorView({ | ||
| typescriptLanguage, | ||
| languageServerSupport(client, "file:///some/file.ts"), | ||
| client.plugin("file:///some/file.ts"), | ||
| ], | ||
@@ -67,0 +67,0 @@ parent: document.body |
+87
-3
| import type * as lsp from "vscode-languageserver-protocol" | ||
| import {showDialog} from "@codemirror/view" | ||
| import {ChangeSet, ChangeDesc, MapMode, Text} from "@codemirror/state" | ||
| import {ChangeSet, ChangeDesc, MapMode, Text, Extension} from "@codemirror/state" | ||
| import {Language} from "@codemirror/language" | ||
| import {LSPPlugin} from "./plugin" | ||
| import {LSPPlugin, lspPlugin} from "./plugin" | ||
| import {toPosition, fromPosition} from "./pos" | ||
| import {Workspace, WorkspaceFile, DefaultWorkspace} from "./workspace" | ||
| import {lspTheme} from "./theme" | ||
@@ -63,3 +64,7 @@ class Request<Result> { | ||
| references: {}, | ||
| diagnostic: {}, | ||
| }, | ||
| window: { | ||
| showMessage: {} | ||
| } | ||
| } | ||
@@ -195,4 +200,31 @@ | ||
| unhandledNotification?: (client: LSPClient, method: string, params: any) => void | ||
| /// Provide a set of extensions, which may be plain CodeMirror | ||
| /// extensions, or objects containing additional client capabilities | ||
| /// or notification handlers. Any CodeMirror extensions provided | ||
| /// here will be included in the extension returned by | ||
| /// [`LSPPlugin.create`](#lsp-client.LSPPlugin^create). | ||
| extensions?: readonly (Extension | LSPClientExtension)[] | ||
| } | ||
| /// Objects of this type can be included in the | ||
| /// [`extensions`](#lsp-client.LSPClientConfig.extensions) option to | ||
| /// `LSPClient` to modularly configure client capabilities or | ||
| /// notification handlers. | ||
| export type LSPClientExtension = { | ||
| /// Extra [client | ||
| /// capabilities](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities) | ||
| /// to send to the server when initializing. The object provided | ||
| /// here will be merged with the capabilities the client provides by | ||
| /// default. | ||
| clientCapabilities?: Record<string, any>, | ||
| /// Additional [notification | ||
| /// handlers](#lsp-client.LSPClientConfig.notificationHandlers). | ||
| /// These will be tried after notification handlers defined directly | ||
| /// in the config object, and then in order of appearance in the | ||
| /// [`extensions`](#lsp-client.LSPClientConfig.extensions) array. | ||
| notificationHandlers?: {[method: string]: (client: LSPClient, params: any) => boolean}, | ||
| /// An optional CodeMirror extension to include. | ||
| editorExtension?: Extension | ||
| } | ||
| /// An LSP client manages a connection to a language server. It should | ||
@@ -219,2 +251,4 @@ /// be explicitly [connected](#lsp-client.LSPClient.connect) before | ||
| private timeout: number | ||
| /// @internal | ||
| extensions: Extension[] = [] | ||
@@ -230,2 +264,7 @@ /// Create a client object. | ||
| this.workspace = config.workspace ? config.workspace(this) : new DefaultWorkspace(this) | ||
| if (config.extensions) for (let ext of config.extensions) { | ||
| if (Array.isArray(ext) || (ext as any).extension) this.extensions.push(ext as Extension) | ||
| else if ((ext as LSPClientExtension).editorExtension) this.extensions.push((ext as LSPClientExtension).editorExtension!) | ||
| } | ||
| } | ||
@@ -244,2 +283,7 @@ | ||
| transport.subscribe(this.receiveMessage) | ||
| let capabilities = clientCapabilities | ||
| if (this.config.extensions) for (let ext of this.config.extensions) { | ||
| let {clientCapabilities} = ext as LSPClientExtension | ||
| if (clientCapabilities) capabilities = mergeCapabilities(capabilities, clientCapabilities) | ||
| } | ||
| this.requestInner<lsp.InitializeParams, lsp.InitializeResult>("initialize", { | ||
@@ -249,3 +293,3 @@ processId: null, | ||
| rootUri: this.config.rootUri || null, | ||
| capabilities: clientCapabilities | ||
| capabilities | ||
| }).promise.then(resp => { | ||
@@ -270,2 +314,25 @@ this.serverCapabilities = resp.capabilities | ||
| /// Create a plugin for this client, to add to an editor | ||
| /// configuration. This extension is necessary to use LSP-related | ||
| /// functionality exported by this package. The returned extension | ||
| /// will include the editor | ||
| /// extensions included in this client's | ||
| /// [configuration](#lsp-client.LSPClientConfig.extensions). | ||
| /// | ||
| /// Creating an editor with this plugin will cause | ||
| /// [`openFile`](#lsp-client.Workspace.openFile) to be called on the | ||
| /// workspace. | ||
| /// | ||
| /// By default, the language ID given to the server for this file is | ||
| /// derived from the editor's language configuration via | ||
| /// [`Language.name`](#language.Language.name). You can pass in | ||
| /// a specific ID as a third parameter. | ||
| plugin(fileURI: string, languageID?: string): Extension { | ||
| return [ | ||
| lspPlugin.of({client: this, uri: fileURI, languageID}), | ||
| lspTheme, | ||
| this.extensions | ||
| ] | ||
| } | ||
| /// Send a `textDocument/didOpen` notification to the server. | ||
@@ -304,2 +371,7 @@ didOpen(file: WorkspaceFile) { | ||
| if (handler && handler(this, value.params)) return | ||
| if (this.config.extensions) for (let ext of this.config.extensions) { | ||
| let {notificationHandlers} = ext as LSPClientExtension | ||
| let handler = notificationHandlers?.[value.method] | ||
| if (handler && handler(this, value.params)) return | ||
| } | ||
| let deflt = defaultNotificationHandlers[value.method] | ||
@@ -437,1 +509,13 @@ if (deflt) deflt(this, value.params) | ||
| } | ||
| function mergeCapabilities(base: any, add?: any) { | ||
| if (add == null) return base | ||
| if (typeof base != "object" || typeof add != "object") return add | ||
| let result: Record<string, any> = {} | ||
| let baseProps = Object.keys(base), addProps = Object.keys(add) | ||
| for (let prop of baseProps) | ||
| result[prop] = addProps.indexOf(prop) > -1 ? mergeCapabilities(base[prop], add[prop]) : base[prop] | ||
| for (let prop of addProps) | ||
| if (baseProps.indexOf(prop) < 0) result[prop] = add[prop] | ||
| return result | ||
| } |
+28
-8
@@ -1,2 +0,2 @@ | ||
| export {Transport, LSPClient, LSPClientConfig, WorkspaceMapping} from "./client" | ||
| export {Transport, LSPClient, LSPClientConfig, LSPClientExtension, WorkspaceMapping} from "./client" | ||
| export {LSPPlugin} from "./plugin" | ||
@@ -11,6 +11,7 @@ export {Workspace, WorkspaceFile} from "./workspace" | ||
| export {findReferences, closeReferencePanel, findReferencesKeymap} from "./references" | ||
| export {serverDiagnostics} from "./diagnostics" | ||
| import {Extension} from "@codemirror/state" | ||
| import {keymap} from "@codemirror/view" | ||
| import {LSPClient} from "./client" | ||
| import {LSPClient, LSPClientExtension} from "./client" | ||
| import {LSPPlugin} from "./plugin" | ||
@@ -24,9 +25,14 @@ import {serverCompletion} from "./completion" | ||
| import {findReferencesKeymap} from "./references" | ||
| import {serverDiagnostics} from "./diagnostics" | ||
| /// Returns an extension that enables the [LSP | ||
| /// plugin](#lsp-client.LSPPlugin) and all other features provided by | ||
| /// this package. You can also pick and choose individual extensions | ||
| /// from the exports. In that case, make sure to also include | ||
| /// [`LSPPlugin.create`](#lsp-client.LSPPlugin^create) in your | ||
| /// extensions, or the others will not work. | ||
| /// plugin](#lsp-client.LSPPlugin) as well as LSP based | ||
| /// autocompletion, hover tooltips, and signature help, along with the | ||
| /// keymaps for reformatting, renaming symbols, jumping to definition, | ||
| /// and finding references. | ||
| /// | ||
| /// This function is deprecated. Prefer to directly use | ||
| /// [`LSPPlugin.create`](#lsp-client.LSPPlugin^create) and either add | ||
| /// the extensions you need directly, or configure them in the client | ||
| /// via [`languageServerExtensions`](#lsp-client.languageServerExtensions). | ||
| export function languageServerSupport(client: LSPClient, uri: string, languageID?: string): Extension { | ||
@@ -38,4 +44,18 @@ return [ | ||
| keymap.of([...formatKeymap, ...renameKeymap, ...jumpToDefinitionKeymap, ...findReferencesKeymap]), | ||
| signatureHelp() | ||
| signatureHelp(), | ||
| ] | ||
| } | ||
| /// This function bundles all the extensions defined in this package, | ||
| /// in a way that can be passed to the | ||
| /// [`extensions`](#lsp-client.LSPClientConfig.extensions) option to | ||
| /// `LSPClient`. | ||
| export function languageServerExtensions(): readonly (Extension | LSPClientExtension)[] { | ||
| return [ | ||
| serverCompletion(), | ||
| hoverTooltips(), | ||
| keymap.of([...formatKeymap, ...renameKeymap, ...jumpToDefinitionKeymap, ...findReferencesKeymap]), | ||
| signatureHelp(), | ||
| serverDiagnostics() | ||
| ] | ||
| } |
+8
-13
@@ -8,3 +8,2 @@ import type * as lsp from "vscode-languageserver-protocol" | ||
| import {toPosition, fromPosition} from "./pos" | ||
| import {lspTheme} from "./theme" | ||
@@ -31,2 +30,3 @@ /// A plugin that connects a given editor to a language server client. | ||
| client.workspace.openFile(uri, languageID, view) | ||
| this.syncedDoc = view.state.doc | ||
| this.unsyncedChanges = ChangeSet.empty(view.state.doc.length) | ||
@@ -63,2 +63,5 @@ } | ||
| /// The version of the document that was synchronized to the server. | ||
| syncedDoc: Text | ||
| /// The changes accumulated in this editor that have not been sent | ||
@@ -72,2 +75,3 @@ /// to the server yet. | ||
| clear() { | ||
| this.syncedDoc = this.view.state.doc | ||
| this.unsyncedChanges = ChangeSet.empty(this.view.state.doc.length) | ||
@@ -92,15 +96,6 @@ } | ||
| /// Create an editor extension that connects that editor to the | ||
| /// given LSP client. This extension is necessary to use LSP-related | ||
| /// functionality exported by this package. Creating an editor with | ||
| /// this plugin will cause | ||
| /// [`openFile`](#lsp-client.Workspace.openFile) to be called on the | ||
| /// workspace. | ||
| /// | ||
| /// By default, the language ID given to the server for this file is | ||
| /// derived from the editor's language configuration via | ||
| /// [`Language.name`](#language.Language.name). You can pass in | ||
| /// a specific ID as a third parameter. | ||
| /// Deprecated. Use | ||
| /// [`LSPClient.plugin`](#lsp-client.LSPClient.plugin) instead. | ||
| static create(client: LSPClient, fileURI: string, languageID?: string): Extension { | ||
| return [lspPlugin.of({client, uri: fileURI, languageID}), lspTheme] | ||
| return client.plugin(fileURI, languageID) | ||
| } | ||
@@ -107,0 +102,0 @@ } |
+6
-0
@@ -7,2 +7,4 @@ ### Client | ||
| @LSPClientExtension | ||
| @Transport | ||
@@ -22,2 +24,4 @@ | ||
| @languageServerExtensions | ||
| @languageServerSupport | ||
@@ -29,2 +33,4 @@ | ||
| @serverDiagnostics | ||
| @hoverTooltips | ||
@@ -31,0 +37,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
273544
8.16%26
4%6322
6.68%