Premier commit déjà bien avancé

This commit is contained in:
2025-11-10 18:33:24 +01:00
commit db4f0508cb
652 changed files with 440521 additions and 0 deletions

View File

@ -0,0 +1,16 @@
name: Trigger CI
on: push
jobs:
build:
name: Dispatch to main repo
runs-on: ubuntu-latest
steps:
- name: Emit repository_dispatch
uses: mvasigh/dispatch-action@main
with:
# You should create a personal access token and store it in your repository
token: ${{ secrets.DISPATCH_AUTH }}
repo: dev
owner: codemirror
event_type: push

View File

@ -0,0 +1,628 @@
## 6.19.1 (2025-10-23)
### Bug fixes
Make sure a completion's info panel is associated with that completion in the accessibility tree.
## 6.19.0 (2025-09-26)
### New features
Completion sections may now set their rank to `dynamic` to indicate their order should be determined by the matching score of their best-matching option.
## 6.18.7 (2025-09-02)
### Bug fixes
Add a binding for Alt-i to trigger `startCompletion`, following VS Code's current default bindings.
Improve handling of nested fields in snippets.
## 6.18.6 (2025-02-12)
### Bug fixes
Fix an issue where the closing character for double-angle quotation marks and full-width brackets was computed incorrectly.
## 6.18.5 (2025-02-11)
### Bug fixes
Fix an issue where clicking on the scrollbar for the completion list could move focus out of the editor.
## 6.18.4 (2024-12-17)
### Bug fixes
Align the behavior of snippet completions with text completions in that they overwrite the selected text.
## 6.18.3 (2024-11-13)
### Bug fixes
Backspacing to the start of the completed range will no longer close the completion tooltip when it was triggered implicitly by typing the character before that range.
## 6.18.2 (2024-10-30)
### Bug fixes
Don't immediately show synchronously updated completions when there are some sources that still need to return.
## 6.18.1 (2024-09-14)
### Bug fixes
Fix an issue where `insertCompletionText` would get confused about the length of the inserted text when it contained CRLF line breaks, and create an invalid selection.
Add Alt-Backtick as additional binding on macOS, where IME can take over Ctrl-Space.
## 6.18.0 (2024-08-05)
### Bug fixes
Style the info element so that newlines are preserved, to make it easier to display multi-line info from a string source.
### New features
When registering an `abort` handler for a completion query, you can now use the `onDocChange` option to indicate that your query should be aborted as soon as the document changes while it is running.
## 6.17.0 (2024-07-03)
### Bug fixes
Fix an issue where completions weren't properly reset when starting a new completion through `activateOnCompletion`.
### New features
`CompletionContext` objects now have a `view` property that holds the editor view when the query context has a view available.
## 6.16.3 (2024-06-19)
### Bug fixes
Avoid adding an `aria-autocomplete` attribute to the editor when there are no active sources active.
## 6.16.2 (2024-05-31)
### Bug fixes
Allow backslash-escaped closing braces inside snippet field names/content.
## 6.16.1 (2024-05-29)
### Bug fixes
Fix a bug where multiple backslashes before a brace in a snippet were all removed.
## 6.16.0 (2024-04-12)
### New features
The new `activateOnCompletion` option allows autocompletion to be configured to chain completion activation for some types of completions.
## 6.15.0 (2024-03-13)
### New features
The new `filterStrict` option can be used to turn off fuzzy matching of completions.
## 6.14.0 (2024-03-10)
### New features
Completion results can now define a `map` method that can be used to adjust position-dependent information for document changes.
## 6.13.0 (2024-02-29)
### New features
Completions may now provide 'commit characters' that, when typed, commit the completion before inserting the character.
## 6.12.0 (2024-01-12)
### Bug fixes
Make sure snippet completions also set `userEvent` to `input.complete`.
Fix a crash when the editor lost focus during an update and autocompletion was active.
Fix a crash when using a snippet that has only one field, but multiple instances of that field.
### New features
The new `activateOnTypingDelay` option allows control over the debounce time before the completions are queried when the user types.
## 6.11.1 (2023-11-27)
### Bug fixes
Fix a bug that caused typing over closed brackets after pressing enter to still not work in many situations.
## 6.11.0 (2023-11-09)
### Bug fixes
Fix an issue that would prevent typing over closed brackets after starting a new line with enter.
### New features
Additional elements rendered in completion options with `addToOptions` are now given access to the editor view.
## 6.10.2 (2023-10-13)
### Bug fixes
Fix a bug that caused `updateSyncTime` to always delay the initial population of the tooltip.
## 6.10.1 (2023-10-11)
### Bug fixes
Fix a bug where picking a selection with the mouse could use the wrong completion if the completion list was updated after being opened.
## 6.10.0 (2023-10-11)
### New features
The new autocompletion configuration option `updateSyncTime` allows control over how long fast sources are held back waiting for slower completion sources.
## 6.9.2 (2023-10-06)
### Bug fixes
Fix a bug in `completeAnyWord` that could cause it to generate invalid regular expressions and crash.
## 6.9.1 (2023-09-14)
### Bug fixes
Make sure the cursor is scrolled into view after inserting completion text.
Make sure scrolling completions into view doesn't get confused when the tooltip is scaled.
## 6.9.0 (2023-07-18)
### New features
Completions may now provide a `displayLabel` property that overrides the way they are displayed in the completion list.
## 6.8.1 (2023-06-23)
### Bug fixes
`acceptCompletion` now returns false (allowing other handlers to take effect) when the completion popup is open but disabled.
## 6.8.0 (2023-06-12)
### New features
The result of `Completion.info` may now include a `destroy` method that will be called when the tooltip is removed.
## 6.7.1 (2023-05-13)
### Bug fixes
Fix a bug that cause incorrect ordering of completions when some results covered input text and others didn't.
## 6.7.0 (2023-05-11)
### New features
The new `hasNextSnippetField` and `hasPrevSnippetField` functions can be used to figure out if the snippet-field-motion commands apply to a given state.
## 6.6.1 (2023-05-03)
### Bug fixes
Fix a bug that made the editor use the completion's original position, rather than its current position, when changes happened in the document while a result was active.
## 6.6.0 (2023-04-27)
### Bug fixes
Fix a bug in `insertCompletionText` that caused it to replace the wrong range when a result set's `to` fell after the cursor.
### New features
Functions returned by `snippet` can now be called without a completion object.
## 6.5.1 (2023-04-13)
### Bug fixes
Keep completions open when interaction with an info tooltip moves focus out of the editor.
## 6.5.0 (2023-04-13)
### Bug fixes
When `closeBrackets` skips a bracket, it now generates a change that overwrites the bracket.
Replace the entire selected range when picking a completion with a non-cursor selection active.
### New features
Completions can now provide a `section` field that is used to group them into sections.
The new `positionInfo` option can be used to provide custom logic for positioning the info tooltips.
## 6.4.2 (2023-02-17)
### Bug fixes
Fix a bug where the apply method created by `snippet` didn't add a `pickedCompletion` annotation to the transactions it created.
## 6.4.1 (2023-02-14)
### Bug fixes
Don't consider node names in trees that aren't the same language as the one at the completion position in `ifIn` and `ifNotIn`.
Make sure completions that exactly match the input get a higher score than those that don't (so that even if the latter has a score boost, it ends up lower in the list).
## 6.4.0 (2022-12-14)
### Bug fixes
Fix an issue where the extension would sometimes try to draw a disabled dialog at an outdated position, leading to plugin crashes.
### New features
A `tooltipClass` option to autocompletion can now be used to add additional CSS classes to the completion tooltip.
## 6.3.4 (2022-11-24)
### Bug fixes
Fix an issue where completion lists could end up being higher than the tooltip they were in.
## 6.3.3 (2022-11-18)
### Bug fixes
Set an explicit `box-sizing` style on completion icons so CSS resets don't mess them up.
Allow closing braces in templates to be escaped with a backslash.
## 6.3.2 (2022-11-15)
### Bug fixes
Fix a regression that could cause the completion dialog to stick around when it should be hidden.
## 6.3.1 (2022-11-14)
### Bug fixes
Fix a regression where transactions for picking a completion (without custom `apply` method) no longer had the `pickedCompletion` annotation.
Reduce flickering for completion sources without `validFor` info by temporarily showing a disabled tooltip while the completion updates.
Make sure completion info tooltips are kept within the space provided by the `tooltipSpace` option.
## 6.3.0 (2022-09-22)
### New features
Close bracket configuration now supports a `stringPrefixes` property that can be used to allow autoclosing of prefixed strings.
## 6.2.0 (2022-09-13)
### New features
Autocompletion now takes an `interactionDelay` option that can be used to control the delay between the time where completion opens and the time where commands like `acceptCompletion` affect it.
## 6.1.1 (2022-09-08)
### Bug fixes
Fix a bug that prevented transactions produced by `deleteBracketPair` from being marked as deletion user events.
Improve positioning of completion info tooltips so they are less likely to stick out of the screen on small displays.
## 6.1.0 (2022-07-19)
### New features
You can now provide a `compareCompletions` option to autocompletion to influence the way completions with the same match score are sorted.
The `selectOnOpen` option to autocompletion can be used to require explicitly selecting a completion option before `acceptCompletion` does anything.
## 6.0.4 (2022-07-07)
### Bug fixes
Remove a leftover `console.log` in bracket closing code.
## 6.0.3 (2022-07-04)
### Bug fixes
Fix a bug that caused `closeBrackets` to not close quotes when at the end of a syntactic construct that starts with a similar quote.
## 6.0.2 (2022-06-15)
### Bug fixes
Declare package dependencies as peer dependencies as an attempt to avoid duplicated package issues.
## 6.0.1 (2022-06-09)
### Bug fixes
Support escaping `${` or `#{` in snippets.
## 6.0.0 (2022-06-08)
### Bug fixes
Scroll the cursor into view when inserting a snippet.
## 0.20.3 (2022-05-30)
### Bug fixes
Add an aria-label to the completion listbox.
Fix a regression that caused transactions generated for completion to not have a `userEvent` annotation.
## 0.20.2 (2022-05-24)
### New features
The package now exports an `insertCompletionText` helper that implements the default behavior for applying a completion.
## 0.20.1 (2022-05-16)
### New features
The new `closeOnBlur` option determines whether the completion tooltip is closed when the editor loses focus.
`CompletionResult` objects with `filter: false` may now have a `getMatch` property that determines the matched range in the options.
## 0.20.0 (2022-04-20)
### Breaking changes
`CompletionResult.span` has been renamed to `validFor`, and may now hold a function as well as a regular expression.
### Bug fixes
Remove code that dropped any options beyond the 300th one when matching and sorting option lists.
Completion will now apply to all cursors when there are multiple cursors.
### New features
`CompletionResult.update` can now be used to implement quick autocompletion updates in a synchronous way.
The @codemirror/closebrackets package was merged into this one.
## 0.19.15 (2022-03-23)
### New features
The `selectedCompletionIndex` function tells you the position of the currently selected completion.
The new `setSelectionCompletion` function creates a state effect that moves the selected completion to a given index.
A completion's `info` method may now return null to indicate that no further info is available.
## 0.19.14 (2022-03-10)
### Bug fixes
Make the ARIA attributes added to the editor during autocompletion spec-compliant.
## 0.19.13 (2022-02-18)
### Bug fixes
Fix an issue where the completion tooltip stayed open if it was explicitly opened and the user backspaced past its start.
Stop snippet filling when a change happens across one of the snippet fields' boundaries.
## 0.19.12 (2022-01-11)
### Bug fixes
Fix completion navigation with PageUp/Down when the completion tooltip isn't part of the view DOM.
## 0.19.11 (2022-01-11)
### Bug fixes
Fix a bug that caused page up/down to only move the selection by two options in the completion tooltip.
## 0.19.10 (2022-01-05)
### Bug fixes
Make sure the info tooltip is hidden when the selected option is scrolled out of view.
Fix a bug in the completion ranking that would sometimes give options that match the input by word start chars higher scores than appropriate.
Options are now sorted (ascending) by length when their match score is otherwise identical.
## 0.19.9 (2021-11-26)
### Bug fixes
Fix an issue where info tooltips would be visible in an inappropriate position when there was no room to place them properly.
## 0.19.8 (2021-11-17)
### Bug fixes
Give the completion tooltip a minimal width, and show ellipsis when completions overflow the tooltip width.
### New features
`autocompletion` now accepts an `aboveCursor` option to make the completion tooltip show up above the cursor.
## 0.19.7 (2021-11-16)
### Bug fixes
Make option deduplication less aggressive, so that options with different `type` or `apply` fields don't get merged.
## 0.19.6 (2021-11-12)
### Bug fixes
Fix an issue where parsing a snippet with a field that was labeled only by a number crashed.
## 0.19.5 (2021-11-09)
### Bug fixes
Make sure info tooltips don't stick out of the bottom of the page.
### New features
The package exports a new function `selectedCompletion`, which can be used to find out which completion is currently selected.
Transactions created by picking a completion now have an annotation (`pickedCompletion`) holding the original completion.
## 0.19.4 (2021-10-24)
### Bug fixes
Don't rely on the platform's highlight colors for the active completion, since those are inconsistent and may not be appropriate for the theme.
Fix incorrect match underline for some kinds of matched completions.
## 0.19.3 (2021-08-31)
### Bug fixes
Improve the sorting of completions by using `localeCompare`.
Fix reading of autocompletions in NVDA screen reader.
### New features
The new `icons` option can be used to turn off icons in the completion list.
The `optionClass` option can now be used to add CSS classes to the options in the completion list.
It is now possible to inject additional content into rendered completion options with the `addToOptions` configuration option.
## 0.19.2 (2021-08-25)
### Bug fixes
Fix an issue where `completeAnyWord` would return results when there was no query and `explicit` was false.
## 0.19.1 (2021-08-11)
### Bug fixes
Fix incorrect versions for @lezer dependencies.
## 0.19.0 (2021-08-11)
### Breaking changes
Update dependencies to 0.19.0
## 0.18.8 (2021-06-30)
### New features
Add an `ifIn` helper function that constrains a completion source to only fire when in a given syntax node. Add support for unfiltered completions
A completion result can now set a `filter: false` property to disable filtering and sorting of completions, when it already did so itself.
## 0.18.7 (2021-06-14)
### Bug fixes
Don't treat continued completions when typing after an explicit completion as explicit.
## 0.18.6 (2021-06-03)
### Bug fixes
Adding or reconfiguring completion sources will now cause them to be activated right away if a completion was active.
### New features
You can now specify multiple types in `Completion.type` by separating them by spaces. Small doc comment tweak for Completion.type
## 0.18.5 (2021-04-23)
### Bug fixes
Fix a regression where snippet field selection didn't work with @codemirror/state 0.18.6.
Fix a bug where snippet fields with different position numbers were inappropriately merged.
## 0.18.4 (2021-04-20)
### Bug fixes
Fix a crash in Safari when moving the selection during composition.
## 0.18.3 (2021-03-15)
### Bug fixes
Adjust to updated @codemirror/tooltip interface.
## 0.18.2 (2021-03-14)
### Bug fixes
Fix unintended ES2020 output (the package contains ES6 code again).
## 0.18.1 (2021-03-11)
### Bug fixes
Stop active completion when all sources resolve without producing any matches.
### New features
`Completion.info` may now return a promise.
## 0.18.0 (2021-03-03)
### Bug fixes
Only preserve selected option across updates when it isn't the first option.
## 0.17.4 (2021-01-18)
### Bug fixes
Fix a styling issue where the selection had become invisible inside snippet fields (when using `drawSelection`).
### New features
Snippet fields can now be selected with the pointing device (so that they are usable on touch devices).
## 0.17.3 (2021-01-18)
### Bug fixes
Fix a bug where uppercase completions would be incorrectly matched against the typed input.
## 0.17.2 (2021-01-12)
### Bug fixes
Don't bind Cmd-Space on macOS, since that already has a system default binding. Use Ctrl-Space for autocompletion.
## 0.17.1 (2021-01-06)
### New features
The package now also exports a CommonJS module.
## 0.17.0 (2020-12-29)
### Breaking changes
First numbered release.

21
frontend/node_modules/@codemirror/autocomplete/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,43 @@
# @codemirror/autocomplete [![NPM version](https://img.shields.io/npm/v/@codemirror/autocomplete.svg)](https://www.npmjs.org/package/@codemirror/autocomplete)
[ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#autocomplete) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/autocomplete/blob/main/CHANGELOG.md) ]
This package implements autocompletion for the
[CodeMirror](https://codemirror.net/) code editor.
The [project page](https://codemirror.net/) has more information, a
number of [examples](https://codemirror.net/examples/) and the
[documentation](https://codemirror.net/docs/).
This code is released under an
[MIT license](https://github.com/codemirror/autocomplete/tree/main/LICENSE).
We aim to be an inclusive, welcoming community. To make that explicit,
we have a [code of
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
to communication around the project.
## Usage
```javascript
import {EditorView} from "@codemirror/view"
import {autocompletion} from "@codemirror/autocomplete"
import {jsonLanguage} from "@codemirror/lang-json"
const view = new EditorView({
parent: document.body,
extensions: [
jsonLanguage,
autocompletion(),
jsonLanguage.data.of({
autocomplete: ["id", "name", "address"]
})
]
})
```
This configuration will just complete the given words anywhere in JSON
context. Most language modules come with more refined autocompletion
built-in, but you can also write your own custom autocompletion
[sources](https://codemirror.net/docs/ref/#autocomplete.CompletionSource)
and associate them with your language this way.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,643 @@
import * as _codemirror_state from '@codemirror/state';
import { EditorState, ChangeDesc, TransactionSpec, Transaction, StateCommand, Facet, Extension, StateEffect } from '@codemirror/state';
import { EditorView, Rect, KeyBinding, Command } from '@codemirror/view';
import * as _lezer_common from '@lezer/common';
/**
Objects type used to represent individual completions.
*/
interface Completion {
/**
The label to show in the completion picker. This is what input
is matched against to determine whether a completion matches (and
how well it matches).
*/
label: string;
/**
An optional override for the completion's visible label. When
using this, matched characters will only be highlighted if you
provide a [`getMatch`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.getMatch)
function.
*/
displayLabel?: string;
/**
An optional short piece of information to show (with a different
style) after the label.
*/
detail?: string;
/**
Additional info to show when the completion is selected. Can be
a plain string or a function that'll render the DOM structure to
show when invoked.
*/
info?: string | ((completion: Completion) => CompletionInfo | Promise<CompletionInfo>);
/**
How to apply the completion. The default is to replace it with
its [label](https://codemirror.net/6/docs/ref/#autocomplete.Completion.label). When this holds a
string, the completion range is replaced by that string. When it
is a function, that function is called to perform the
completion. If it fires a transaction, it is responsible for
adding the [`pickedCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.pickedCompletion)
annotation to it.
*/
apply?: string | ((view: EditorView, completion: Completion, from: number, to: number) => void);
/**
The type of the completion. This is used to pick an icon to show
for the completion. Icons are styled with a CSS class created by
appending the type name to `"cm-completionIcon-"`. You can
define or restyle icons by defining these selectors. The base
library defines simple icons for `class`, `constant`, `enum`,
`function`, `interface`, `keyword`, `method`, `namespace`,
`property`, `text`, `type`, and `variable`.
Multiple types can be provided by separating them with spaces.
*/
type?: string;
/**
When this option is selected, and one of these characters is
typed, insert the completion before typing the character.
*/
commitCharacters?: readonly string[];
/**
When given, should be a number from -99 to 99 that adjusts how
this completion is ranked compared to other completions that
match the input as well as this one. A negative number moves it
down the list, a positive number moves it up.
*/
boost?: number;
/**
Can be used to divide the completion list into sections.
Completions in a given section (matched by name) will be grouped
together, with a heading above them. Options without section
will appear above all sections. A string value is equivalent to
a `{name}` object.
*/
section?: string | CompletionSection;
}
/**
The type returned from
[`Completion.info`](https://codemirror.net/6/docs/ref/#autocomplete.Completion.info). May be a DOM
node, null to indicate there is no info, or an object with an
optional `destroy` method that cleans up the node.
*/
type CompletionInfo = Node | null | {
dom: Node;
destroy?(): void;
};
/**
Object used to describe a completion
[section](https://codemirror.net/6/docs/ref/#autocomplete.Completion.section). It is recommended to
create a shared object used by all the completions in a given
section.
*/
interface CompletionSection {
/**
The name of the section. If no `render` method is present, this
will be displayed above the options.
*/
name: string;
/**
An optional function that renders the section header. Since the
headers are shown inside a list, you should make sure the
resulting element has a `display: list-item` style.
*/
header?: (section: CompletionSection) => HTMLElement;
/**
By default, sections are ordered alphabetically by name. To
specify an explicit order, `rank` can be used. Sections with a
lower rank will be shown above sections with a higher rank.
When set to `"dynamic"`, the section's position compared to
other dynamic sections depends on the matching score of the
best-matching option in the sections.
*/
rank?: number | "dynamic";
}
/**
An instance of this is passed to completion source functions.
*/
declare class CompletionContext {
/**
The editor state that the completion happens in.
*/
readonly state: EditorState;
/**
The position at which the completion is happening.
*/
readonly pos: number;
/**
Indicates whether completion was activated explicitly, or
implicitly by typing. The usual way to respond to this is to
only return completions when either there is part of a
completable entity before the cursor, or `explicit` is true.
*/
readonly explicit: boolean;
/**
The editor view. May be undefined if the context was created
in a situation where there is no such view available, such as
in synchronous updates via
[`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
or when called by test code.
*/
readonly view?: EditorView | undefined;
/**
Create a new completion context. (Mostly useful for testing
completion sources—in the editor, the extension will create
these for you.)
*/
constructor(
/**
The editor state that the completion happens in.
*/
state: EditorState,
/**
The position at which the completion is happening.
*/
pos: number,
/**
Indicates whether completion was activated explicitly, or
implicitly by typing. The usual way to respond to this is to
only return completions when either there is part of a
completable entity before the cursor, or `explicit` is true.
*/
explicit: boolean,
/**
The editor view. May be undefined if the context was created
in a situation where there is no such view available, such as
in synchronous updates via
[`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
or when called by test code.
*/
view?: EditorView | undefined);
/**
Get the extent, content, and (if there is a token) type of the
token before `this.pos`.
*/
tokenBefore(types: readonly string[]): {
from: number;
to: number;
text: string;
type: _lezer_common.NodeType;
} | null;
/**
Get the match of the given expression directly before the
cursor.
*/
matchBefore(expr: RegExp): {
from: number;
to: number;
text: string;
} | null;
/**
Yields true when the query has been aborted. Can be useful in
asynchronous queries to avoid doing work that will be ignored.
*/
get aborted(): boolean;
/**
Allows you to register abort handlers, which will be called when
the query is
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
By default, running queries will not be aborted for regular
typing or backspacing, on the assumption that they are likely to
return a result with a
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
allows the result to be used after all. Passing `onDocChange:
true` will cause this query to be aborted for any document
change.
*/
addEventListener(type: "abort", listener: () => void, options?: {
onDocChange: boolean;
}): void;
}
/**
Given a a fixed array of options, return an autocompleter that
completes them.
*/
declare function completeFromList(list: readonly (string | Completion)[]): CompletionSource;
/**
Wrap the given completion source so that it will only fire when the
cursor is in a syntax node with one of the given names.
*/
declare function ifIn(nodes: readonly string[], source: CompletionSource): CompletionSource;
/**
Wrap the given completion source so that it will not fire when the
cursor is in a syntax node with one of the given names.
*/
declare function ifNotIn(nodes: readonly string[], source: CompletionSource): CompletionSource;
/**
The function signature for a completion source. Such a function
may return its [result](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult)
synchronously or as a promise. Returning null indicates no
completions are available.
*/
type CompletionSource = (context: CompletionContext) => CompletionResult | null | Promise<CompletionResult | null>;
/**
Interface for objects returned by completion sources.
*/
interface CompletionResult {
/**
The start of the range that is being completed.
*/
from: number;
/**
The end of the range that is being completed. Defaults to the
main cursor position.
*/
to?: number;
/**
The completions returned. These don't have to be compared with
the input by the source—the autocompletion system will do its
own matching (against the text between `from` and `to`) and
sorting.
*/
options: readonly Completion[];
/**
When given, further typing or deletion that causes the part of
the document between ([mapped](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) `from`
and `to` to match this regular expression or predicate function
will not query the completion source again, but continue with
this list of options. This can help a lot with responsiveness,
since it allows the completion list to be updated synchronously.
*/
validFor?: RegExp | ((text: string, from: number, to: number, state: EditorState) => boolean);
/**
By default, the library filters and scores completions. Set
`filter` to `false` to disable this, and cause your completions
to all be included, in the order they were given. When there are
other sources, unfiltered completions appear at the top of the
list of completions. `validFor` must not be given when `filter`
is `false`, because it only works when filtering.
*/
filter?: boolean;
/**
When [`filter`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.filter) is set to
`false` or a completion has a
[`displayLabel`](https://codemirror.net/6/docs/ref/#autocomplete.Completion.displayLabel), this
may be provided to compute the ranges on the label that match
the input. Should return an array of numbers where each pair of
adjacent numbers provide the start and end of a range. The
second argument, the match found by the library, is only passed
when `filter` isn't `false`.
*/
getMatch?: (completion: Completion, matched?: readonly number[]) => readonly number[];
/**
Synchronously update the completion result after typing or
deletion. If given, this should not do any expensive work, since
it will be called during editor state updates. The function
should make sure (similar to
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor)) that the
completion still applies in the new state.
*/
update?: (current: CompletionResult, from: number, to: number, context: CompletionContext) => CompletionResult | null;
/**
When results contain position-dependent information in, for
example, `apply` methods, you can provide this method to update
the result for transactions that happen after the query. It is
not necessary to update `from` and `to`—those are tracked
automatically.
*/
map?: (current: CompletionResult, changes: ChangeDesc) => CompletionResult | null;
/**
Set a default set of [commit
characters](https://codemirror.net/6/docs/ref/#autocomplete.Completion.commitCharacters) for all
options in this result.
*/
commitCharacters?: readonly string[];
}
/**
This annotation is added to transactions that are produced by
picking a completion.
*/
declare const pickedCompletion: _codemirror_state.AnnotationType<Completion>;
/**
Helper function that returns a transaction spec which inserts a
completion's text in the main selection range, and any other
selection range that has the same text in front of it.
*/
declare function insertCompletionText(state: EditorState, text: string, from: number, to: number): TransactionSpec;
interface CompletionConfig {
/**
When enabled (defaults to true), autocompletion will start
whenever the user types something that can be completed.
*/
activateOnTyping?: boolean;
/**
When given, if a completion that matches the predicate is
picked, reactivate completion again as if it was typed normally.
*/
activateOnCompletion?: (completion: Completion) => boolean;
/**
The amount of time to wait for further typing before querying
completion sources via
[`activateOnTyping`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.activateOnTyping).
Defaults to 100, which should be fine unless your completion
source is very slow and/or doesn't use `validFor`.
*/
activateOnTypingDelay?: number;
/**
By default, when completion opens, the first option is selected
and can be confirmed with
[`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion). When this
is set to false, the completion widget starts with no completion
selected, and the user has to explicitly move to a completion
before you can confirm one.
*/
selectOnOpen?: boolean;
/**
Override the completion sources used. By default, they will be
taken from the `"autocomplete"` [language
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) (which should hold
[completion sources](https://codemirror.net/6/docs/ref/#autocomplete.CompletionSource) or arrays
of [completions](https://codemirror.net/6/docs/ref/#autocomplete.Completion)).
*/
override?: readonly CompletionSource[] | null;
/**
Determines whether the completion tooltip is closed when the
editor loses focus. Defaults to true.
*/
closeOnBlur?: boolean;
/**
The maximum number of options to render to the DOM.
*/
maxRenderedOptions?: number;
/**
Set this to false to disable the [default completion
keymap](https://codemirror.net/6/docs/ref/#autocomplete.completionKeymap). (This requires you to
add bindings to control completion yourself. The bindings should
probably have a higher precedence than other bindings for the
same keys.)
*/
defaultKeymap?: boolean;
/**
By default, completions are shown below the cursor when there is
space. Setting this to true will make the extension put the
completions above the cursor when possible.
*/
aboveCursor?: boolean;
/**
When given, this may return an additional CSS class to add to
the completion dialog element.
*/
tooltipClass?: (state: EditorState) => string;
/**
This can be used to add additional CSS classes to completion
options.
*/
optionClass?: (completion: Completion) => string;
/**
By default, the library will render icons based on the
completion's [type](https://codemirror.net/6/docs/ref/#autocomplete.Completion.type) in front of
each option. Set this to false to turn that off.
*/
icons?: boolean;
/**
This option can be used to inject additional content into
options. The `render` function will be called for each visible
completion, and should produce a DOM node to show. `position`
determines where in the DOM the result appears, relative to
other added widgets and the standard content. The default icons
have position 20, the label position 50, and the detail position
80.
*/
addToOptions?: {
render: (completion: Completion, state: EditorState, view: EditorView) => Node | null;
position: number;
}[];
/**
By default, [info](https://codemirror.net/6/docs/ref/#autocomplete.Completion.info) tooltips are
placed to the side of the selected completion. This option can
be used to override that. It will be given rectangles for the
list of completions, the selected option, the info element, and
the availble [tooltip
space](https://codemirror.net/6/docs/ref/#view.tooltips^config.tooltipSpace), and should return
style and/or class strings for the info element.
*/
positionInfo?: (view: EditorView, list: Rect, option: Rect, info: Rect, space: Rect) => {
style?: string;
class?: string;
};
/**
The comparison function to use when sorting completions with the same
match score. Defaults to using
[`localeCompare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare).
*/
compareCompletions?: (a: Completion, b: Completion) => number;
/**
When set to true (the default is false), turn off fuzzy matching
of completions and only show those that start with the text the
user typed. Only takes effect for results where
[`filter`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.filter) isn't false.
*/
filterStrict?: boolean;
/**
By default, commands relating to an open completion only take
effect 75 milliseconds after the completion opened, so that key
presses made before the user is aware of the tooltip don't go to
the tooltip. This option can be used to configure that delay.
*/
interactionDelay?: number;
/**
When there are multiple asynchronous completion sources, this
controls how long the extension waits for a slow source before
displaying results from faster sources. Defaults to 100
milliseconds.
*/
updateSyncTime?: number;
}
/**
Convert a snippet template to a function that can
[apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written
using syntax like this:
"for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"
Each `${}` placeholder (you may also use `#{}`) indicates a field
that the user can fill in. Its name, if any, will be the default
content for the field.
When the snippet is activated by calling the returned function,
the code is inserted at the given position. Newlines in the
template are indented by the indentation of the start line, plus
one [indent unit](https://codemirror.net/6/docs/ref/#language.indentUnit) per tab character after
the newline.
On activation, (all instances of) the first field are selected.
The user can move between fields with Tab and Shift-Tab as long as
the fields are active. Moving to the last field or moving the
cursor out of the current field deactivates the fields.
The order of fields defaults to textual order, but you can add
numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
a custom order.
To include a literal `{` or `}` in your template, put a backslash
in front of it. This will be removed and the brace will not be
interpreted as indicating a placeholder.
*/
declare function snippet(template: string): (editor: {
state: EditorState;
dispatch: (tr: Transaction) => void;
}, completion: Completion | null, from: number, to: number) => void;
/**
A command that clears the active snippet, if any.
*/
declare const clearSnippet: StateCommand;
/**
Move to the next snippet field, if available.
*/
declare const nextSnippetField: StateCommand;
/**
Move to the previous snippet field, if available.
*/
declare const prevSnippetField: StateCommand;
/**
Check if there is an active snippet with a next field for
`nextSnippetField` to move to.
*/
declare function hasNextSnippetField(state: EditorState): boolean;
/**
Returns true if there is an active snippet and a previous field
for `prevSnippetField` to move to.
*/
declare function hasPrevSnippetField(state: EditorState): boolean;
/**
A facet that can be used to configure the key bindings used by
snippets. The default binds Tab to
[`nextSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.nextSnippetField), Shift-Tab to
[`prevSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.prevSnippetField), and Escape
to [`clearSnippet`](https://codemirror.net/6/docs/ref/#autocomplete.clearSnippet).
*/
declare const snippetKeymap: Facet<readonly KeyBinding[], readonly KeyBinding[]>;
/**
Create a completion from a snippet. Returns an object with the
properties from `completion`, plus an `apply` function that
applies the snippet.
*/
declare function snippetCompletion(template: string, completion: Completion): Completion;
/**
Returns a command that moves the completion selection forward or
backward by the given amount.
*/
declare function moveCompletionSelection(forward: boolean, by?: "option" | "page"): Command;
/**
Accept the current completion.
*/
declare const acceptCompletion: Command;
/**
Explicitly start autocompletion.
*/
declare const startCompletion: Command;
/**
Close the currently active completion.
*/
declare const closeCompletion: Command;
/**
A completion source that will scan the document for words (using a
[character categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer)), and
return those as completions.
*/
declare const completeAnyWord: CompletionSource;
/**
Configures bracket closing behavior for a syntax (via
[language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)) using the `"closeBrackets"`
identifier.
*/
interface CloseBracketConfig {
/**
The opening brackets to close. Defaults to `["(", "[", "{", "'",
'"']`. Brackets may be single characters or a triple of quotes
(as in `"'''"`).
*/
brackets?: string[];
/**
Characters in front of which newly opened brackets are
automatically closed. Closing always happens in front of
whitespace. Defaults to `")]}:;>"`.
*/
before?: string;
/**
When determining whether a given node may be a string, recognize
these prefixes before the opening quote.
*/
stringPrefixes?: string[];
}
/**
Extension to enable bracket-closing behavior. When a closeable
bracket is typed, its closing bracket is immediately inserted
after the cursor. When closing a bracket directly in front of a
closing bracket inserted by the extension, the cursor moves over
that bracket.
*/
declare function closeBrackets(): Extension;
/**
Command that implements deleting a pair of matching brackets when
the cursor is between them.
*/
declare const deleteBracketPair: StateCommand;
/**
Close-brackets related key bindings. Binds Backspace to
[`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair).
*/
declare const closeBracketsKeymap: readonly KeyBinding[];
/**
Implements the extension's behavior on text insertion. If the
given string counts as a bracket in the language around the
selection, and replacing the selection with it requires custom
behavior (inserting a closing version or skipping past a
previously-closed bracket), this function returns a transaction
representing that custom behavior. (You only need this if you want
to programmatically insert brackets—the
[`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will
take care of running this for user input.)
*/
declare function insertBracket(state: EditorState, bracket: string): Transaction | null;
/**
Returns an extension that enables autocompletion.
*/
declare function autocompletion(config?: CompletionConfig): Extension;
/**
Basic keybindings for autocompletion.
- Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
- Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
- ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
- ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
- PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
- PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
- Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
*/
declare const completionKeymap: readonly KeyBinding[];
/**
Get the current completion status. When completions are available,
this will return `"active"`. When completions are pending (in the
process of being queried), this returns `"pending"`. Otherwise, it
returns `null`.
*/
declare function completionStatus(state: EditorState): null | "active" | "pending";
/**
Returns the available completions as an array.
*/
declare function currentCompletions(state: EditorState): readonly Completion[];
/**
Return the currently selected completion, if any.
*/
declare function selectedCompletion(state: EditorState): Completion | null;
/**
Returns the currently selected position in the active completion
list, or null if no completions are active.
*/
declare function selectedCompletionIndex(state: EditorState): number | null;
/**
Create an effect that can be attached to a transaction to change
the currently selected completion.
*/
declare function setSelectedCompletion(index: number): StateEffect<unknown>;
export { type CloseBracketConfig, type Completion, CompletionContext, type CompletionInfo, type CompletionResult, type CompletionSection, type CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeBrackets, closeBracketsKeymap, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, deleteBracketPair, hasNextSnippetField, hasPrevSnippetField, ifIn, ifNotIn, insertBracket, insertCompletionText, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, selectedCompletionIndex, setSelectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };

View File

@ -0,0 +1,643 @@
import * as _codemirror_state from '@codemirror/state';
import { EditorState, ChangeDesc, TransactionSpec, Transaction, StateCommand, Facet, Extension, StateEffect } from '@codemirror/state';
import { EditorView, Rect, KeyBinding, Command } from '@codemirror/view';
import * as _lezer_common from '@lezer/common';
/**
Objects type used to represent individual completions.
*/
interface Completion {
/**
The label to show in the completion picker. This is what input
is matched against to determine whether a completion matches (and
how well it matches).
*/
label: string;
/**
An optional override for the completion's visible label. When
using this, matched characters will only be highlighted if you
provide a [`getMatch`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.getMatch)
function.
*/
displayLabel?: string;
/**
An optional short piece of information to show (with a different
style) after the label.
*/
detail?: string;
/**
Additional info to show when the completion is selected. Can be
a plain string or a function that'll render the DOM structure to
show when invoked.
*/
info?: string | ((completion: Completion) => CompletionInfo | Promise<CompletionInfo>);
/**
How to apply the completion. The default is to replace it with
its [label](https://codemirror.net/6/docs/ref/#autocomplete.Completion.label). When this holds a
string, the completion range is replaced by that string. When it
is a function, that function is called to perform the
completion. If it fires a transaction, it is responsible for
adding the [`pickedCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.pickedCompletion)
annotation to it.
*/
apply?: string | ((view: EditorView, completion: Completion, from: number, to: number) => void);
/**
The type of the completion. This is used to pick an icon to show
for the completion. Icons are styled with a CSS class created by
appending the type name to `"cm-completionIcon-"`. You can
define or restyle icons by defining these selectors. The base
library defines simple icons for `class`, `constant`, `enum`,
`function`, `interface`, `keyword`, `method`, `namespace`,
`property`, `text`, `type`, and `variable`.
Multiple types can be provided by separating them with spaces.
*/
type?: string;
/**
When this option is selected, and one of these characters is
typed, insert the completion before typing the character.
*/
commitCharacters?: readonly string[];
/**
When given, should be a number from -99 to 99 that adjusts how
this completion is ranked compared to other completions that
match the input as well as this one. A negative number moves it
down the list, a positive number moves it up.
*/
boost?: number;
/**
Can be used to divide the completion list into sections.
Completions in a given section (matched by name) will be grouped
together, with a heading above them. Options without section
will appear above all sections. A string value is equivalent to
a `{name}` object.
*/
section?: string | CompletionSection;
}
/**
The type returned from
[`Completion.info`](https://codemirror.net/6/docs/ref/#autocomplete.Completion.info). May be a DOM
node, null to indicate there is no info, or an object with an
optional `destroy` method that cleans up the node.
*/
type CompletionInfo = Node | null | {
dom: Node;
destroy?(): void;
};
/**
Object used to describe a completion
[section](https://codemirror.net/6/docs/ref/#autocomplete.Completion.section). It is recommended to
create a shared object used by all the completions in a given
section.
*/
interface CompletionSection {
/**
The name of the section. If no `render` method is present, this
will be displayed above the options.
*/
name: string;
/**
An optional function that renders the section header. Since the
headers are shown inside a list, you should make sure the
resulting element has a `display: list-item` style.
*/
header?: (section: CompletionSection) => HTMLElement;
/**
By default, sections are ordered alphabetically by name. To
specify an explicit order, `rank` can be used. Sections with a
lower rank will be shown above sections with a higher rank.
When set to `"dynamic"`, the section's position compared to
other dynamic sections depends on the matching score of the
best-matching option in the sections.
*/
rank?: number | "dynamic";
}
/**
An instance of this is passed to completion source functions.
*/
declare class CompletionContext {
/**
The editor state that the completion happens in.
*/
readonly state: EditorState;
/**
The position at which the completion is happening.
*/
readonly pos: number;
/**
Indicates whether completion was activated explicitly, or
implicitly by typing. The usual way to respond to this is to
only return completions when either there is part of a
completable entity before the cursor, or `explicit` is true.
*/
readonly explicit: boolean;
/**
The editor view. May be undefined if the context was created
in a situation where there is no such view available, such as
in synchronous updates via
[`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
or when called by test code.
*/
readonly view?: EditorView | undefined;
/**
Create a new completion context. (Mostly useful for testing
completion sources—in the editor, the extension will create
these for you.)
*/
constructor(
/**
The editor state that the completion happens in.
*/
state: EditorState,
/**
The position at which the completion is happening.
*/
pos: number,
/**
Indicates whether completion was activated explicitly, or
implicitly by typing. The usual way to respond to this is to
only return completions when either there is part of a
completable entity before the cursor, or `explicit` is true.
*/
explicit: boolean,
/**
The editor view. May be undefined if the context was created
in a situation where there is no such view available, such as
in synchronous updates via
[`CompletionResult.update`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.update)
or when called by test code.
*/
view?: EditorView | undefined);
/**
Get the extent, content, and (if there is a token) type of the
token before `this.pos`.
*/
tokenBefore(types: readonly string[]): {
from: number;
to: number;
text: string;
type: _lezer_common.NodeType;
} | null;
/**
Get the match of the given expression directly before the
cursor.
*/
matchBefore(expr: RegExp): {
from: number;
to: number;
text: string;
} | null;
/**
Yields true when the query has been aborted. Can be useful in
asynchronous queries to avoid doing work that will be ignored.
*/
get aborted(): boolean;
/**
Allows you to register abort handlers, which will be called when
the query is
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
By default, running queries will not be aborted for regular
typing or backspacing, on the assumption that they are likely to
return a result with a
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
allows the result to be used after all. Passing `onDocChange:
true` will cause this query to be aborted for any document
change.
*/
addEventListener(type: "abort", listener: () => void, options?: {
onDocChange: boolean;
}): void;
}
/**
Given a a fixed array of options, return an autocompleter that
completes them.
*/
declare function completeFromList(list: readonly (string | Completion)[]): CompletionSource;
/**
Wrap the given completion source so that it will only fire when the
cursor is in a syntax node with one of the given names.
*/
declare function ifIn(nodes: readonly string[], source: CompletionSource): CompletionSource;
/**
Wrap the given completion source so that it will not fire when the
cursor is in a syntax node with one of the given names.
*/
declare function ifNotIn(nodes: readonly string[], source: CompletionSource): CompletionSource;
/**
The function signature for a completion source. Such a function
may return its [result](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult)
synchronously or as a promise. Returning null indicates no
completions are available.
*/
type CompletionSource = (context: CompletionContext) => CompletionResult | null | Promise<CompletionResult | null>;
/**
Interface for objects returned by completion sources.
*/
interface CompletionResult {
/**
The start of the range that is being completed.
*/
from: number;
/**
The end of the range that is being completed. Defaults to the
main cursor position.
*/
to?: number;
/**
The completions returned. These don't have to be compared with
the input by the source—the autocompletion system will do its
own matching (against the text between `from` and `to`) and
sorting.
*/
options: readonly Completion[];
/**
When given, further typing or deletion that causes the part of
the document between ([mapped](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) `from`
and `to` to match this regular expression or predicate function
will not query the completion source again, but continue with
this list of options. This can help a lot with responsiveness,
since it allows the completion list to be updated synchronously.
*/
validFor?: RegExp | ((text: string, from: number, to: number, state: EditorState) => boolean);
/**
By default, the library filters and scores completions. Set
`filter` to `false` to disable this, and cause your completions
to all be included, in the order they were given. When there are
other sources, unfiltered completions appear at the top of the
list of completions. `validFor` must not be given when `filter`
is `false`, because it only works when filtering.
*/
filter?: boolean;
/**
When [`filter`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.filter) is set to
`false` or a completion has a
[`displayLabel`](https://codemirror.net/6/docs/ref/#autocomplete.Completion.displayLabel), this
may be provided to compute the ranges on the label that match
the input. Should return an array of numbers where each pair of
adjacent numbers provide the start and end of a range. The
second argument, the match found by the library, is only passed
when `filter` isn't `false`.
*/
getMatch?: (completion: Completion, matched?: readonly number[]) => readonly number[];
/**
Synchronously update the completion result after typing or
deletion. If given, this should not do any expensive work, since
it will be called during editor state updates. The function
should make sure (similar to
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor)) that the
completion still applies in the new state.
*/
update?: (current: CompletionResult, from: number, to: number, context: CompletionContext) => CompletionResult | null;
/**
When results contain position-dependent information in, for
example, `apply` methods, you can provide this method to update
the result for transactions that happen after the query. It is
not necessary to update `from` and `to`—those are tracked
automatically.
*/
map?: (current: CompletionResult, changes: ChangeDesc) => CompletionResult | null;
/**
Set a default set of [commit
characters](https://codemirror.net/6/docs/ref/#autocomplete.Completion.commitCharacters) for all
options in this result.
*/
commitCharacters?: readonly string[];
}
/**
This annotation is added to transactions that are produced by
picking a completion.
*/
declare const pickedCompletion: _codemirror_state.AnnotationType<Completion>;
/**
Helper function that returns a transaction spec which inserts a
completion's text in the main selection range, and any other
selection range that has the same text in front of it.
*/
declare function insertCompletionText(state: EditorState, text: string, from: number, to: number): TransactionSpec;
interface CompletionConfig {
/**
When enabled (defaults to true), autocompletion will start
whenever the user types something that can be completed.
*/
activateOnTyping?: boolean;
/**
When given, if a completion that matches the predicate is
picked, reactivate completion again as if it was typed normally.
*/
activateOnCompletion?: (completion: Completion) => boolean;
/**
The amount of time to wait for further typing before querying
completion sources via
[`activateOnTyping`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.activateOnTyping).
Defaults to 100, which should be fine unless your completion
source is very slow and/or doesn't use `validFor`.
*/
activateOnTypingDelay?: number;
/**
By default, when completion opens, the first option is selected
and can be confirmed with
[`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion). When this
is set to false, the completion widget starts with no completion
selected, and the user has to explicitly move to a completion
before you can confirm one.
*/
selectOnOpen?: boolean;
/**
Override the completion sources used. By default, they will be
taken from the `"autocomplete"` [language
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) (which should hold
[completion sources](https://codemirror.net/6/docs/ref/#autocomplete.CompletionSource) or arrays
of [completions](https://codemirror.net/6/docs/ref/#autocomplete.Completion)).
*/
override?: readonly CompletionSource[] | null;
/**
Determines whether the completion tooltip is closed when the
editor loses focus. Defaults to true.
*/
closeOnBlur?: boolean;
/**
The maximum number of options to render to the DOM.
*/
maxRenderedOptions?: number;
/**
Set this to false to disable the [default completion
keymap](https://codemirror.net/6/docs/ref/#autocomplete.completionKeymap). (This requires you to
add bindings to control completion yourself. The bindings should
probably have a higher precedence than other bindings for the
same keys.)
*/
defaultKeymap?: boolean;
/**
By default, completions are shown below the cursor when there is
space. Setting this to true will make the extension put the
completions above the cursor when possible.
*/
aboveCursor?: boolean;
/**
When given, this may return an additional CSS class to add to
the completion dialog element.
*/
tooltipClass?: (state: EditorState) => string;
/**
This can be used to add additional CSS classes to completion
options.
*/
optionClass?: (completion: Completion) => string;
/**
By default, the library will render icons based on the
completion's [type](https://codemirror.net/6/docs/ref/#autocomplete.Completion.type) in front of
each option. Set this to false to turn that off.
*/
icons?: boolean;
/**
This option can be used to inject additional content into
options. The `render` function will be called for each visible
completion, and should produce a DOM node to show. `position`
determines where in the DOM the result appears, relative to
other added widgets and the standard content. The default icons
have position 20, the label position 50, and the detail position
80.
*/
addToOptions?: {
render: (completion: Completion, state: EditorState, view: EditorView) => Node | null;
position: number;
}[];
/**
By default, [info](https://codemirror.net/6/docs/ref/#autocomplete.Completion.info) tooltips are
placed to the side of the selected completion. This option can
be used to override that. It will be given rectangles for the
list of completions, the selected option, the info element, and
the availble [tooltip
space](https://codemirror.net/6/docs/ref/#view.tooltips^config.tooltipSpace), and should return
style and/or class strings for the info element.
*/
positionInfo?: (view: EditorView, list: Rect, option: Rect, info: Rect, space: Rect) => {
style?: string;
class?: string;
};
/**
The comparison function to use when sorting completions with the same
match score. Defaults to using
[`localeCompare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare).
*/
compareCompletions?: (a: Completion, b: Completion) => number;
/**
When set to true (the default is false), turn off fuzzy matching
of completions and only show those that start with the text the
user typed. Only takes effect for results where
[`filter`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.filter) isn't false.
*/
filterStrict?: boolean;
/**
By default, commands relating to an open completion only take
effect 75 milliseconds after the completion opened, so that key
presses made before the user is aware of the tooltip don't go to
the tooltip. This option can be used to configure that delay.
*/
interactionDelay?: number;
/**
When there are multiple asynchronous completion sources, this
controls how long the extension waits for a slow source before
displaying results from faster sources. Defaults to 100
milliseconds.
*/
updateSyncTime?: number;
}
/**
Convert a snippet template to a function that can
[apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written
using syntax like this:
"for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"
Each `${}` placeholder (you may also use `#{}`) indicates a field
that the user can fill in. Its name, if any, will be the default
content for the field.
When the snippet is activated by calling the returned function,
the code is inserted at the given position. Newlines in the
template are indented by the indentation of the start line, plus
one [indent unit](https://codemirror.net/6/docs/ref/#language.indentUnit) per tab character after
the newline.
On activation, (all instances of) the first field are selected.
The user can move between fields with Tab and Shift-Tab as long as
the fields are active. Moving to the last field or moving the
cursor out of the current field deactivates the fields.
The order of fields defaults to textual order, but you can add
numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
a custom order.
To include a literal `{` or `}` in your template, put a backslash
in front of it. This will be removed and the brace will not be
interpreted as indicating a placeholder.
*/
declare function snippet(template: string): (editor: {
state: EditorState;
dispatch: (tr: Transaction) => void;
}, completion: Completion | null, from: number, to: number) => void;
/**
A command that clears the active snippet, if any.
*/
declare const clearSnippet: StateCommand;
/**
Move to the next snippet field, if available.
*/
declare const nextSnippetField: StateCommand;
/**
Move to the previous snippet field, if available.
*/
declare const prevSnippetField: StateCommand;
/**
Check if there is an active snippet with a next field for
`nextSnippetField` to move to.
*/
declare function hasNextSnippetField(state: EditorState): boolean;
/**
Returns true if there is an active snippet and a previous field
for `prevSnippetField` to move to.
*/
declare function hasPrevSnippetField(state: EditorState): boolean;
/**
A facet that can be used to configure the key bindings used by
snippets. The default binds Tab to
[`nextSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.nextSnippetField), Shift-Tab to
[`prevSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.prevSnippetField), and Escape
to [`clearSnippet`](https://codemirror.net/6/docs/ref/#autocomplete.clearSnippet).
*/
declare const snippetKeymap: Facet<readonly KeyBinding[], readonly KeyBinding[]>;
/**
Create a completion from a snippet. Returns an object with the
properties from `completion`, plus an `apply` function that
applies the snippet.
*/
declare function snippetCompletion(template: string, completion: Completion): Completion;
/**
Returns a command that moves the completion selection forward or
backward by the given amount.
*/
declare function moveCompletionSelection(forward: boolean, by?: "option" | "page"): Command;
/**
Accept the current completion.
*/
declare const acceptCompletion: Command;
/**
Explicitly start autocompletion.
*/
declare const startCompletion: Command;
/**
Close the currently active completion.
*/
declare const closeCompletion: Command;
/**
A completion source that will scan the document for words (using a
[character categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer)), and
return those as completions.
*/
declare const completeAnyWord: CompletionSource;
/**
Configures bracket closing behavior for a syntax (via
[language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)) using the `"closeBrackets"`
identifier.
*/
interface CloseBracketConfig {
/**
The opening brackets to close. Defaults to `["(", "[", "{", "'",
'"']`. Brackets may be single characters or a triple of quotes
(as in `"'''"`).
*/
brackets?: string[];
/**
Characters in front of which newly opened brackets are
automatically closed. Closing always happens in front of
whitespace. Defaults to `")]}:;>"`.
*/
before?: string;
/**
When determining whether a given node may be a string, recognize
these prefixes before the opening quote.
*/
stringPrefixes?: string[];
}
/**
Extension to enable bracket-closing behavior. When a closeable
bracket is typed, its closing bracket is immediately inserted
after the cursor. When closing a bracket directly in front of a
closing bracket inserted by the extension, the cursor moves over
that bracket.
*/
declare function closeBrackets(): Extension;
/**
Command that implements deleting a pair of matching brackets when
the cursor is between them.
*/
declare const deleteBracketPair: StateCommand;
/**
Close-brackets related key bindings. Binds Backspace to
[`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair).
*/
declare const closeBracketsKeymap: readonly KeyBinding[];
/**
Implements the extension's behavior on text insertion. If the
given string counts as a bracket in the language around the
selection, and replacing the selection with it requires custom
behavior (inserting a closing version or skipping past a
previously-closed bracket), this function returns a transaction
representing that custom behavior. (You only need this if you want
to programmatically insert brackets—the
[`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will
take care of running this for user input.)
*/
declare function insertBracket(state: EditorState, bracket: string): Transaction | null;
/**
Returns an extension that enables autocompletion.
*/
declare function autocompletion(config?: CompletionConfig): Extension;
/**
Basic keybindings for autocompletion.
- Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
- Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
- ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
- ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
- PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
- PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
- Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
*/
declare const completionKeymap: readonly KeyBinding[];
/**
Get the current completion status. When completions are available,
this will return `"active"`. When completions are pending (in the
process of being queried), this returns `"pending"`. Otherwise, it
returns `null`.
*/
declare function completionStatus(state: EditorState): null | "active" | "pending";
/**
Returns the available completions as an array.
*/
declare function currentCompletions(state: EditorState): readonly Completion[];
/**
Return the currently selected completion, if any.
*/
declare function selectedCompletion(state: EditorState): Completion | null;
/**
Returns the currently selected position in the active completion
list, or null if no completions are active.
*/
declare function selectedCompletionIndex(state: EditorState): number | null;
/**
Create an effect that can be attached to a transaction to change
the currently selected completion.
*/
declare function setSelectedCompletion(index: number): StateEffect<unknown>;
export { type CloseBracketConfig, type Completion, CompletionContext, type CompletionInfo, type CompletionResult, type CompletionSection, type CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeBrackets, closeBracketsKeymap, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, deleteBracketPair, hasNextSnippetField, hasPrevSnippetField, ifIn, ifNotIn, insertBracket, insertCompletionText, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, selectedCompletionIndex, setSelectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,41 @@
{
"name": "@codemirror/autocomplete",
"version": "6.19.1",
"description": "Autocompletion for the CodeMirror code editor",
"scripts": {
"test": "cm-runtests",
"prepare": "cm-buildhelper src/index.ts"
},
"keywords": [
"editor",
"code"
],
"author": {
"name": "Marijn Haverbeke",
"email": "marijn@haverbeke.berlin",
"url": "http://marijnhaverbeke.nl"
},
"type": "module",
"main": "dist/index.cjs",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"types": "dist/index.d.ts",
"module": "dist/index.js",
"sideEffects": false,
"license": "MIT",
"dependencies": {
"@codemirror/language": "^6.0.0",
"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.17.0",
"@lezer/common": "^1.0.0"
},
"devDependencies": {
"@codemirror/buildhelper": "^1.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/codemirror/autocomplete.git"
}
}