cm-tarnation
Version:
An alternative parser for CodeMirror 6
47 lines (46 loc) • 1.92 kB
TypeScript
import type { CompletionContext } from "@codemirror/autocomplete";
import type { TarnationLanguage } from "../language";
import type { AutocompleteHandler } from "../types";
/** Handles autocompletion for a {@link TarnationLanguage}. */
export declare class Autocompleter {
language: TarnationLanguage;
/** A map of node names to completion handlers. */
handlers: Map<string, AutocompleteHandler>;
/** @param language - The {@link TarnationLanguage} to provide completions for. */
constructor(language: TarnationLanguage);
/** Configuration for the autocomplete. */
get config(): {
[key: string]: boolean | AutocompleteHandler | undefined;
_alsoTypeNames?: boolean | undefined;
_alsoEmitNames?: boolean | undefined;
_traverseUpwards?: boolean | undefined;
"*"?: AutocompleteHandler | undefined;
};
/**
* Gets a handler via a name,
*
* @param handler - The name of the handler.
*/
private get;
/**
* Gets an autocomplete handler for a {@link Node}.
*
* @param type - The {@link Node} to get a handler for.
*/
private getHandlerFor;
/**
* Tries to get an autocomplete handler for a `SyntaxNode`. Will traverse
* up the node's parents if allowed to do so in the configuration.
*
* @param node - The `SyntaxNode` to get a handler for.
* @param root - Internal parameter. Defaults to true.
*/
private traverse;
/**
* CodeMirror autocompletion handler function. Delegates to autocomplete
* handlers defined in the language's configuartion.
*
* @param context - The `CompletionContext` provided by CodeMirror.
*/
handle(context: CompletionContext): import("@codemirror/autocomplete").CompletionResult | Promise<import("@codemirror/autocomplete").CompletionResult | null> | null;
}