@codemirror/lsp-client
Advanced tools
+6
-0
@@ -0,1 +1,7 @@ | ||
| ## 6.2.0 (2025-10-27) | ||
| ### New features | ||
| `serverCompletion` now takes an option `validFor` that can be used to configure the regexp used in the result. | ||
| ## 6.1.2 (2025-09-10) | ||
@@ -2,0 +8,0 @@ |
+8
-0
@@ -472,2 +472,10 @@ import * as lsp from 'vscode-languageserver-protocol'; | ||
| override?: boolean; | ||
| /** | ||
| Set a custom | ||
| [`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) expression | ||
| to use in the completion results. By default, the library uses an | ||
| expression that accepts word characters, optionally prefixed by | ||
| any non-word prefixes found in the results. | ||
| */ | ||
| validFor?: RegExp; | ||
| }): Extension; | ||
@@ -474,0 +482,0 @@ /** |
+8
-0
@@ -472,2 +472,10 @@ import * as lsp from 'vscode-languageserver-protocol'; | ||
| override?: boolean; | ||
| /** | ||
| Set a custom | ||
| [`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) expression | ||
| to use in the completion results. By default, the library uses an | ||
| expression that accepts word characters, optionally prefixed by | ||
| any non-word prefixes found in the results. | ||
| */ | ||
| validFor?: RegExp; | ||
| }): Extension; | ||
@@ -474,0 +482,0 @@ /** |
+1
-1
| { | ||
| "name": "@codemirror/lsp-client", | ||
| "version": "6.1.2", | ||
| "version": "6.2.0", | ||
| "description": "Language server protocol client for CodeMirror", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+18
-4
| import type * as lsp from "vscode-languageserver-protocol" | ||
| import {EditorState, Extension} from "@codemirror/state" | ||
| import {EditorState, Extension, Facet} from "@codemirror/state" | ||
| import {CompletionSource, Completion, CompletionContext, snippet, autocompletion} from "@codemirror/autocomplete" | ||
@@ -15,11 +15,24 @@ import {LSPPlugin} from "./plugin" | ||
| override?: boolean | ||
| /// Set a custom | ||
| /// [`validFor`](#autocomplete.CompletionResult.validFor) expression | ||
| /// to use in the completion results. By default, the library uses an | ||
| /// expression that accepts word characters, optionally prefixed by | ||
| /// any non-word prefixes found in the results. | ||
| validFor?: RegExp | ||
| } = {}): Extension { | ||
| let result: Extension[] | ||
| if (config.override) { | ||
| return autocompletion({override: [serverCompletionSource]}) | ||
| result = [autocompletion({override: [serverCompletionSource]})] | ||
| } else { | ||
| let data = [{autocomplete: serverCompletionSource}] | ||
| return [autocompletion(), EditorState.languageData.of(() => data)] | ||
| result = [autocompletion(), EditorState.languageData.of(() => data)] | ||
| } | ||
| if (config.validFor) result.push(completionConfig.of({validFor: config.validFor})) | ||
| return result | ||
| } | ||
| const completionConfig = Facet.define<{validFor: RegExp}, {validFor: RegExp | null}>({ | ||
| combine: results => results.length ? results[0] : {validFor: null} | ||
| }) | ||
| function getCompletions(plugin: LSPPlugin, pos: number, context: lsp.CompletionContext, abort?: CompletionContext) { | ||
@@ -72,2 +85,3 @@ if (plugin.client.hasCapability("completionProvider") === false) return Promise.resolve(null) | ||
| let defaultCommitChars = result.itemDefaults?.commitCharacters | ||
| let config = context.state.facet(completionConfig) | ||
@@ -93,3 +107,3 @@ return { | ||
| commitCharacters: defaultCommitChars, | ||
| validFor: prefixRegexp(result.items), | ||
| validFor: config.validFor ?? prefixRegexp(result.items), | ||
| map: (result, changes) => ({...result, from: changes.mapPos(result.from)}), | ||
@@ -96,0 +110,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
278133
0.83%6428
0.58%