2023-08-28 23:12:15 +08:00
|
|
|
import { system } from "$sb/syscalls.ts";
|
2024-02-09 04:00:45 +08:00
|
|
|
import { CompleteEvent } from "$type/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",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|