import type { IGrammar, IRawGrammar, IRawTheme, StateStack } from 'vscode-textmate'; import type { Languages, ScopeName } from '../grammars/index.ts'; /** The options for the TextMate registry. */ export interface RegistryOptions { /** The function to get a grammar from the TextMate registry. */ getGrammar: (scopeName: ScopeName) => Promise; /** The function to get a theme from the TextMate registry. */ getTheme: (theme: Theme) => Promise; } /** The grammar definition from the TextMate registry. */ export type TextMateGrammar = IGrammar; /** The raw grammar definition from the TextMate registry. */ export type TextMateGrammarRaw = IRawGrammar; /** The registry of TextMate grammars and themes. */ export type TextMateRegistry = { getColorMap: () => string[]; loadGrammar: (grammar: Grammar) => Promise; setTheme: (theme: TextMateThemeRaw) => void; }; /** The raw theme definition from the TextMate registry. */ export type TextMateThemeRaw = IRawTheme & { type?: 'dark' | 'light'; colors?: Record; semanticTokenColors?: Record; tokenColors?: TextMateTokenColor[]; settings?: IRawTheme['settings']; }; /** The color of a single token. */ export interface TextMateTokenColor { name?: string; scope: string | string[]; settings: TextMateTokenSettings; } /** The settings of a single token. */ export interface TextMateTokenSettings { foreground?: string; background?: string; fontStyle?: string; } /** The style of a single token. */ export interface TextMateTokenStyle { color: string; backgroundColor: string; fontStyle: string; fontWeight: string; textDecoration: string; [key: string]: string | undefined; } /** A single token generated by the tokenizer. */ export interface TextMateToken { value: string; start: number; end: number; style: TextMateTokenStyle; hasTextStyles: boolean; isBaseColor: boolean; isWhiteSpace: boolean; } /** The grammar state to seed the tokenization with per theme. */ export type GrammarState = Array; export interface TokenizeOptions { /** * The grammar state(s) to seed the tokenization with. * * - If a single state is provided, it is applied to all themes. * - If an array is provided, each entry is used as the state for the * corresponding theme index. */ grammarState?: GrammarState; /** The maximum time in milliseconds to spend tokenizing a single line. */ timeLimit?: number; } export type TokenizedLines = TextMateToken[][]; interface GrammarMetadata extends IRawGrammar { name?: string; aliases?: string[]; } export declare class Registry { #private; constructor(options: RegistryOptions); fetchGrammar: (scopeName: ScopeName) => Promise; loadGrammar(language: Languages): Promise; fetchTheme(name: Theme): Promise; setTheme(theme: TextMateThemeRaw): void; getThemeColors(): string[]; } export declare class Tokenizer { #private; constructor(registryOptions: RegistryOptions); /** * Stream tokens line-by-line for the given source. * Useful for long-running operations where incremental results are desired. */ stream(source: string, language: Languages, themes: Theme[], options?: TokenizeOptions): AsyncGenerator; /** Tokenize the given source for multiple themes. */ tokenize(source: string, language: Languages, themes: Theme[], options?: TokenizeOptions): Promise; /** * Returns the last grammar states per theme from the most recent * `tokenize`/`stream` call. The array indexes correspond to the `themes` * array passed into that call. */ getGrammarState(): GrammarState; } export {};