feat: add completions API and scanning logic
Implement a new completions system that scans markdown files for dice notation and headings. The server now exposes a `/__COMPLETIONS.json` endpoint and automatically recomputes the completion index when files are added, updated, or deleted.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Completion index — orchestrates all registered completion sources.
|
||||
*/
|
||||
|
||||
import { diceSource } from "./sources/dice.js";
|
||||
import { linksSource } from "./sources/links.js";
|
||||
import type { CompletionSource, CompletionsPayload } from "./types.js";
|
||||
|
||||
export type {
|
||||
CompletionsPayload,
|
||||
DiceCompletion,
|
||||
LinkCompletion,
|
||||
} from "./types.js";
|
||||
|
||||
/** Registered sources — open for extension */
|
||||
const sources: CompletionSource[] = [diceSource, linksSource];
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user