2024-08-07 02:11:38 +08:00
|
|
|
import { system } from "@silverbulletmd/silverbullet/syscalls";
|
2024-07-30 23:33:33 +08:00
|
|
|
import type { CompleteEvent } from "../../plug-api/types.ts";
|
2022-09-06 20:36:06 +08:00
|
|
|
|
2022-12-21 21:55:24 +08:00
|
|
|
export async function commandComplete(completeEvent: CompleteEvent) {
|
2024-02-23 20:50:59 +08:00
|
|
|
const match = /\{\[([^\]\[]*)$/.exec(completeEvent.linePrefix);
|
2022-12-21 21:55:24 +08:00
|
|
|
|
|
|
|
if (!match) {
|
2022-09-06 20:36:06 +08:00
|
|
|
return null;
|
|
|
|
}
|
2022-10-14 21:11:33 +08:00
|
|
|
const allCommands = await system.listCommands();
|
2022-09-06 20:36:06 +08:00
|
|
|
|
|
|
|
return {
|
2022-12-21 21:55:24 +08:00
|
|
|
from: completeEvent.pos - match[1].length,
|
2022-09-06 20:36:06 +08:00
|
|
|
options: Object.keys(allCommands).map((commandName) => ({
|
|
|
|
label: commandName,
|
|
|
|
type: "command",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|