/** * Basic node with start and length to represent a range in the code */ interface NodeStartLength { /** 0-indexed position of the node in the file */ start: number; /** The length of the node */ length: number; } interface NodeBase extends NodeStartLength, Position { } interface NodeHover extends NodeBase { type: 'hover'; /** The string content of the node this represents (mainly for debugging) */ target: string; /** The base LSP response (the type) */ text: string; /** Attached JSDoc info */ docs?: string; /** JSDoc tags */ tags?: [name: string, text: string | undefined][]; } interface NodeHighlight extends NodeBase { type: 'highlight'; /** The annotation message */ text?: string; } interface NodeQuery extends Omit { type: 'query'; } interface CompletionEntry { name: string; kind?: string; } interface NodeCompletion extends NodeBase { type: 'completion'; /** Results for completions at a particular point */ completions: CompletionEntry[]; completionsPrefix: string; } type ErrorLevel = 'warning' | 'error' | 'suggestion' | 'message'; interface NodeError extends NodeBase { type: 'error'; id?: string; /** * Error level * When not provided, defaults to 'error' */ level?: ErrorLevel; /** * Error code */ code?: number | string; /** * Error message */ text: string; /** * The filename of the file the error is in */ filename?: string; } interface NodeTag extends NodeBase { type: 'tag'; /** What was the name of the tag */ name: string; /** What was the text after the `// @tag: ` string (optional because you could do // @tag on it's own line without the ':') */ text?: string; } type TwoslashNode = NodeHighlight | NodeHover | NodeQuery | NodeCompletion | NodeError | NodeTag; type NodeWithoutPosition = Omit | Omit | Omit | Omit | Omit | Omit; type NodeErrorWithoutPosition = Omit; interface Position { /** * 0-indexed line number */ line: number; /** * 0-indexed column number */ character: number; } type Range = [start: number, end: number]; interface TwoslashGenericResult { /** * The output code, could be TypeScript, but could also be a JS/JSON/d.ts */ code: string; /** * Extension of the output code */ extension?: string; /** * Nodes containing various bits of information about the code */ nodes: TwoslashNode[]; } type TwoslashGenericFunction = (code: string, filename?: string, options?: Options) => TwoslashGenericResult; export type { CompletionEntry, ErrorLevel, NodeBase, NodeCompletion, NodeError, NodeErrorWithoutPosition, NodeHighlight, NodeHover, NodeQuery, NodeStartLength, NodeTag, NodeWithoutPosition, Position, Range, TwoslashGenericFunction, TwoslashGenericResult, TwoslashNode };