UNPKG

cm-tarnation

Version:

An alternative parser for CodeMirror 6

90 lines (89 loc) 3.71 kB
import { CompletionContext } from "@codemirror/autocomplete"; import type { SyntaxNode, Tree } from "@lezer/common"; import { Node } from "../grammar/node"; /** * An extended form of CodeMirror's `CompletionContext` provided to * Tarnation autocomplete handlers. */ export declare class TarnationCompletionContext extends CompletionContext { /** The {@link Node} type used by the node at the current position. */ type: Node; /** The syntax tree of the editor. */ tree: Tree; /** The node at the current position. */ node: SyntaxNode; /** Will be true if the completion handler was called via the parent chain. */ traversed: boolean; private _around?; private _text?; /** * Mutates a CodeMirror `CompletionContext` into a * {@link TarnationCompletionContext}. * * @param context - The `CompletionContext` to mutate. * @param type - The {@link Node} type. * @param tree - The syntax tree of the editor. * @param node - The node at the current position. * @param traversed - Set to `true` if the completion handler should be * called via the parent chain. */ static mutate(context: CompletionContext, type: Node, tree: Tree, node: SyntaxNode, traversed: boolean): TarnationCompletionContext; /** The `SyntaxNode` surrounding the current position. */ get around(): SyntaxNode | null; /** The {@link Node} type of the {@link around} node. */ get aroundType(): Node | null; /** The starting position of the current node. */ get from(): number; /** The ending positon of the current node. */ get to(): number; /** The string of text covered by the current node. */ get text(): string; /** * Gets the {@link Node} type of a `SyntaxNode`. * * @param node - The `SyntaxNode` to get the type from. */ grammarType(node: SyntaxNode | null | undefined): Node | null; /** * Gets the string of text covered by a `SyntaxNode`. * * @param node - The `SyntaxNode` to get the text from. */ textOf(node: SyntaxNode | null | undefined): string | null; /** * Gets the parents of a `SyntaxNode`. * * @param node - The `SyntaxNode` to get the parents from. * @param max - The maximum number of parents to traverse upwards for. */ parentsOf(node: SyntaxNode | null | undefined, max?: number): SyntaxNode[]; /** * Finds the first parent of a `SyntaxNode` that matches the given name(s). * * @param node - The `SyntaxNode` to find a parent for. * @param parent - The name(s) of the parent to find. * @param max - The maximum number of parents to traverse upwards for. */ findParentOf(node: SyntaxNode | null | undefined, parent: string | string[], max?: number): SyntaxNode | null; /** * Shorthand for using {@link findParentsOf} on the current node. * * @param parent - The name(s) of the parent to find. * @param max - The maximum number of parents to traverse upwards for. */ parent(parent: string | string[], max?: number): SyntaxNode | null; /** * Shorthand for running {@link parentsOf} on the current node. * * @param level - The maximum number of parents to get. */ parents(level?: number): SyntaxNode | null; /** * Checks if the current position is inbetween the two given nodes. * * @param left - The left node to check for. * @param right - The right node to check for. Defaults to the same as * the `left` node. */ isInbetween(left: string, right?: string): boolean; }