2022-12-21 13:55:24 +00:00
|
|
|
import { system } from "$sb/silverbullet-syscall/mod.ts";
|
|
|
|
import { CompleteEvent } from "../../plug-api/app_event.ts";
|
2022-09-06 12:36:06 +00:00
|
|
|
|
2022-12-21 13:55:24 +00:00
|
|
|
export async function commandComplete(completeEvent: CompleteEvent) {
|
|
|
|
const match = /\{\[([^\]]*)$/.exec(completeEvent.linePrefix);
|
|
|
|
|
|
|
|
if (!match) {
|
2022-09-06 12:36:06 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-10-14 13:11:33 +00:00
|
|
|
const allCommands = await system.listCommands();
|
2022-09-06 12:36:06 +00:00
|
|
|
|
|
|
|
return {
|
2022-12-21 13:55:24 +00:00
|
|
|
from: completeEvent.pos - match[1].length,
|
2022-09-06 12:36:06 +00:00
|
|
|
options: Object.keys(allCommands).map((commandName) => ({
|
|
|
|
label: commandName,
|
|
|
|
type: "command",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|