46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
/**
|
|
* Completion index — orchestrates all registered completion sources.
|
|
*/
|
|
|
|
import { linksSource } from "./sources/links.js";
|
|
import type { ProcessedBlocks } from "./block-processor.js";
|
|
import type { CompletionsPayload } from "./types.js";
|
|
import type { DirectiveScanResult } from "./directive-scanner.js";
|
|
|
|
export type {
|
|
CompletionsPayload,
|
|
DiceCompletion,
|
|
LinkCompletion,
|
|
SparkTableCompletion,
|
|
VarDeclaration,
|
|
TagModifier,
|
|
} from "./types.js";
|
|
|
|
/**
|
|
* Build completions from the content index, pre-collected blocks,
|
|
* and directive scan results.
|
|
* Called at server startup and on any file change.
|
|
*/
|
|
export function scanCompletions(
|
|
index: Record<string, string>,
|
|
blocks: ProcessedBlocks,
|
|
directiveResults: DirectiveScanResult[],
|
|
): CompletionsPayload {
|
|
const links = linksSource.scan(index) as CompletionsPayload["links"];
|
|
|
|
// Merge all directive scan results
|
|
const dice: CompletionsPayload["dice"] = [];
|
|
const sparkTables: CompletionsPayload["sparkTables"] = [];
|
|
for (const dr of directiveResults) {
|
|
dice.push(...dr.dice);
|
|
sparkTables.push(...dr.sparkTables);
|
|
}
|
|
|
|
return {
|
|
dice,
|
|
links,
|
|
sparkTables,
|
|
declarations: blocks.declarations,
|
|
tagModifiers: blocks.tagModifiers,
|
|
};
|
|
} |