code/editor/CodeCompletion
import { … } from 'zidane-ui/code/editor'ui/src/code/editor/CodeCompletion.tsx
Functions#
matchWordFunction#
How text matches typed: every typed character in order, the first one
at a word start. Class 3: a case-exact prefix, 2: a prefix, 1: all hits on
word starts (camelCase, snake_case), 0: anywhere. null: no match.
function matchWord(
text: string,
typed: string,
): { positions: number[]; rank: number } | nullParameters
| Name | Type | Description |
|---|---|---|
| text | string | The label (or filter text) to match. |
| typed | string | The word typed so far. |
Returns
{ positions: number[]; rank: number } | nullrankCompletionsFunction#
The items matching typed, best first: match class, then the server's own order.
function rankCompletions(items: readonly CompletionItem[], typed: string): RankedItem[]Parameters
| Name | Type | Description |
|---|---|---|
| items | readonly CompletionItem[] | The answer's items, in the server's order. |
| typed | string | The word typed so far. |
Returns
useCompletionFunction#
Drives completion for one editor: call onChange with the editor's changes and render node.
function useCompletion(
source: CompletionSource | null,
handle: RefObject<CodeEditorHandle | null>,
): { close: () => void; node: Element | null; onChange: (next: string, changes: readonly EditChange[]) => void; open: boolean }Parameters
| Name | Type | Description |
|---|---|---|
| source | CompletionSource | null | Where suggestions come from; |
| handle | RefObject<CodeEditorHandle | null> | The editor's handle (its host takes the keys, its editor the edits). |
Returns
{ close: () => void; node: Element | null; onChange: (next: string, changes: readonly EditChange[]) => void; open: boolean }Interfaces#
CompletionAnswerInterface#
What a completion request answers.
interface CompletionAnswerProperties
| Name | Type | Description |
|---|---|---|
| busy? | string | The server is still loading. |
| id | number | Answer id, passed back to |
| incomplete | boolean | Typing on must ask again instead of filtering. |
| items | CompletionItem[] | The suggestions, in the server's order. |
CompletionDetailInterface#
The rest of an item, fetched for the highlighted item and on accept.
interface CompletionDetailProperties
| Name | Type | Description |
|---|---|---|
| additionalEdits? | { newText: string; range: { end: Pos; start: Pos } }[] | More edits to apply on accept (an auto-import), in 0-based positions; only those ahead of the inserted text apply. |
| detail? | string | Full type or signature, shown in the documentation panel when it says more than the item's own. |
| documentation? | string | Documentation, shown as plain text under the menu. |
CompletionItemInterface#
One suggestion (the LSP item, flattened by the source).
interface CompletionItemProperties
| Name | Type | Description |
|---|---|---|
| cursor? | { end: number; start: number } | Caret (or selected placeholder) inside |
| detail? | string | Type or signature, shown dimmed after the label. |
| filterText? | string | Text the typed word is matched against instead of |
| insertText | string | Text that replaces the typed word on accept. |
| kind? | string | LSP kind as a word ( |
| label | string | Text shown in the menu; the typed word is matched against it unless |
| preselect? | boolean | Selected when the menu opens on an empty word. |
| range? | { end: Pos; start: Pos } | The span the item replaces at request time; absent: the word before the caret. |
| sortText? | string | Sort key within a match class; absent: |
CompletionSourceInterface#
Where the menu's suggestions come from (the Files panel's language server).
interface CompletionSourceProperties
| Name | Type | Description |
|---|---|---|
| complete | (text: string, line: number, character: number, trigger?: string) => Promise<CompletionAnswer> | Suggestions at a 0-based caret in |
| resolve? | (id: number, index: number) => Promise<CompletionDetail | null> | The rest of item |
RankedItemInterface#
An item that matches what was typed, with the label characters that matched.
interface RankedItemProperties
| Name | Type | Description |
|---|---|---|
| index | number | Index in the answer (for |
| item | CompletionItem | The suggestion. |
| matches | number[] | Label indices of the matched characters, for highlighting; empty when it matched on |