Lua script block prioritization
parent
6d42423e8d
commit
11a2adbea6
|
@ -28,7 +28,12 @@ export class SpaceLuaEnvironment {
|
||||||
) {
|
) {
|
||||||
const allScripts: ScriptObject[] = await system.invokeFunction(
|
const allScripts: ScriptObject[] = await system.invokeFunction(
|
||||||
"index.queryObjects",
|
"index.queryObjects",
|
||||||
["space-lua", {}],
|
["space-lua", {
|
||||||
|
orderBy: [{
|
||||||
|
expr: ["attr", "priority"],
|
||||||
|
desc: true,
|
||||||
|
}],
|
||||||
|
}],
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
this.env = buildLuaEnv(system, scriptEnv);
|
this.env = buildLuaEnv(system, scriptEnv);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { indexObjects } from "./api.ts";
|
||||||
import { space } from "@silverbulletmd/silverbullet/syscalls";
|
import { space } from "@silverbulletmd/silverbullet/syscalls";
|
||||||
export type ScriptObject = ObjectValue<{
|
export type ScriptObject = ObjectValue<{
|
||||||
script: string;
|
script: string;
|
||||||
|
priority?: number;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export async function indexSpaceScript({ name, tree }: IndexTreeEvent) {
|
export async function indexSpaceScript({ name, tree }: IndexTreeEvent) {
|
||||||
|
@ -50,10 +51,14 @@ export async function indexSpaceLua({ name, tree }: IndexTreeEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const codeText = codeTextNode.children![0].text!;
|
const codeText = codeTextNode.children![0].text!;
|
||||||
|
// Parse out "-- priority: <number>"
|
||||||
|
const priority = codeText.match(/--\s*priority:\s*(-?\d+)/)?.[1];
|
||||||
|
|
||||||
allScripts.push({
|
allScripts.push({
|
||||||
ref: `${name}@${t.from!}`,
|
ref: `${name}@${t.from!}`,
|
||||||
tag: "space-lua",
|
tag: "space-lua",
|
||||||
script: codeText,
|
script: codeText,
|
||||||
|
priority: priority !== undefined ? +priority : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await indexObjects<ScriptObject>(name, allScripts);
|
await indexObjects<ScriptObject>(name, allScripts);
|
||||||
|
@ -65,9 +70,13 @@ export async function indexSpaceLuaFile(name: string) {
|
||||||
}
|
}
|
||||||
console.log("Indexing space lua file", name);
|
console.log("Indexing space lua file", name);
|
||||||
const data = await space.readFile(name);
|
const data = await space.readFile(name);
|
||||||
|
const code = new TextDecoder().decode(data);
|
||||||
|
// Parse out "-- priority: <number>"
|
||||||
|
const priority = code.match(/--\s*priority:\s*(-?\d+)/)?.[1];
|
||||||
await indexObjects<ScriptObject>(name, [{
|
await indexObjects<ScriptObject>(name, [{
|
||||||
ref: `${name}`,
|
ref: `${name}`,
|
||||||
tag: "space-lua",
|
tag: "space-lua",
|
||||||
script: new TextDecoder().decode(data),
|
script: code,
|
||||||
|
priority: priority !== undefined ? +priority : undefined,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue