refactor(completions): centralize content scanning
Add a browser-safe ContentRegistry owning path and inline content stores, then derive completions from it. Remove the old block-processor, directive-scanner, and link-source modules in favor of scanDoc, deriveCompletions, and injectSparkDirectives, and register an inline resolver for the frontend file index.
This commit is contained in:
@@ -24,6 +24,20 @@ let fileIndex: FileIndex | null = null;
|
||||
let indexLoadPromise: Promise<void> | null = null;
|
||||
let activeSource: "cli" | "folder" | null = null;
|
||||
|
||||
/**
|
||||
* Optional registry for resolving inline content ids (set by the journal
|
||||
* completions module). When present, `getIndexedData` resolves ids that
|
||||
* aren't real files through it.
|
||||
*/
|
||||
let inlineResolver: ((path: string) => string | null) | null = null;
|
||||
|
||||
/** Register a resolver for inline content ids (see journal/completions). */
|
||||
export function setInlineResolver(
|
||||
fn: ((path: string) => string | null) | null,
|
||||
): void {
|
||||
inlineResolver = fn;
|
||||
}
|
||||
|
||||
/** Currently active directory handle (if folder source) */
|
||||
let activeDirHandle: FileSystemDirectoryHandle | null = null;
|
||||
|
||||
@@ -181,6 +195,15 @@ export async function getIndexedData(path: string): Promise<string> {
|
||||
if (fileIndex && fileIndex[path]) {
|
||||
return fileIndex[path];
|
||||
}
|
||||
// Resolve inline content ids through the registry before fetching.
|
||||
if (inlineResolver) {
|
||||
const inline = inlineResolver(path);
|
||||
if (inline !== null) {
|
||||
fileIndex = fileIndex || {};
|
||||
fileIndex[path] = inline;
|
||||
return inline;
|
||||
}
|
||||
}
|
||||
const res = await fetch(path);
|
||||
const content = await res.text();
|
||||
fileIndex = fileIndex || {};
|
||||
|
||||
Reference in New Issue
Block a user