2022-10-14 13:11:33 +00:00
|
|
|
import { events } from "$sb/plugos-syscall/mod.ts";
|
2023-05-23 18:53:53 +00:00
|
|
|
import { CompleteEvent } from "$sb/app_event.ts";
|
2023-07-24 09:09:17 +00:00
|
|
|
import { buildHandebarOptions } from "./util.ts";
|
|
|
|
import type { PageMeta } from "../../web/types.ts";
|
2022-07-04 13:07:27 +00:00
|
|
|
|
2022-12-21 13:55:24 +00:00
|
|
|
export async function queryComplete(completeEvent: CompleteEvent) {
|
|
|
|
const match = /#query ([\w\-_]+)*$/.exec(completeEvent.linePrefix);
|
|
|
|
if (!match) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-07-04 13:07:27 +00:00
|
|
|
|
2022-12-21 13:55:24 +00:00
|
|
|
const allEvents = await events.listEvents();
|
2022-07-04 13:07:27 +00:00
|
|
|
|
2022-12-21 13:55:24 +00:00
|
|
|
return {
|
|
|
|
from: completeEvent.pos - match[1].length,
|
|
|
|
options: allEvents
|
|
|
|
.filter((eventName) => eventName.startsWith("query:"))
|
|
|
|
.map((source) => ({
|
|
|
|
label: source.substring("query:".length),
|
|
|
|
})),
|
|
|
|
};
|
2022-07-04 13:07:27 +00:00
|
|
|
}
|
2023-07-02 09:25:32 +00:00
|
|
|
|
|
|
|
export function handlebarHelperComplete(completeEvent: CompleteEvent) {
|
|
|
|
const match = /\{\{([\w@]*)$/.exec(completeEvent.linePrefix);
|
|
|
|
if (!match) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const handlebarOptions = buildHandebarOptions({ name: "" } as PageMeta);
|
|
|
|
const allCompletions = Object.keys(handlebarOptions.helpers).concat(
|
|
|
|
Object.keys(handlebarOptions.data).map((key) => `@${key}`),
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
from: completeEvent.pos - match[1].length,
|
|
|
|
options: allCompletions
|
|
|
|
.map((name) => ({
|
|
|
|
label: name,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|