42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
/**
|
|
* Completion index — orchestrates all registered completion sources.
|
|
*/
|
|
|
|
import { diceSource } from "./sources/dice.js";
|
|
import { linksSource } from "./sources/links.js";
|
|
import { sparkTablesSource } from "./sources/spark-tables.js";
|
|
import { statsSource } from "./sources/stats.js";
|
|
import type { CompletionSource, CompletionsPayload } from "./types.js";
|
|
|
|
export type {
|
|
CompletionsPayload,
|
|
DiceCompletion,
|
|
LinkCompletion,
|
|
SparkTableCompletion,
|
|
StatDef,
|
|
} from "./types.js";
|
|
|
|
/** Registered sources — open for extension */
|
|
const sources: CompletionSource[] = [
|
|
diceSource,
|
|
linksSource,
|
|
sparkTablesSource,
|
|
statsSource,
|
|
];
|
|
|
|
/**
|
|
* Scan the full content index and return structured completion data.
|
|
* Called at server startup and on any file change.
|
|
*/
|
|
export function scanCompletions(
|
|
index: Record<string, string>,
|
|
): CompletionsPayload {
|
|
const payload: Record<string, unknown[]> = {};
|
|
|
|
for (const source of sources) {
|
|
payload[source.key] = source.scan(index);
|
|
}
|
|
|
|
return payload as unknown as CompletionsPayload;
|
|
}
|