diff --git a/plugs/core/Library/Std/Lua.md b/plugs/core/Library/Std/Lua.md index 635012d0..e3c51e67 100644 --- a/plugs/core/Library/Std/Lua.md +++ b/plugs/core/Library/Std/Lua.md @@ -84,14 +84,14 @@ event.listen { -- Function defined in Lua table.insert(options, { label = key .. "(" .. table.concat(val.body.parameters, ", ") ..")", - apply = key .. "(", + apply = key, detail = "Lua function" }) else -- Builtin table.insert(options, { label = key .. "()", - apply = key .. "(", + apply = key, detail = "Lua built-in" }) end diff --git a/plugs/core/std.ts b/plugs/core/std.ts index 095c0c29..c921fabb 100644 --- a/plugs/core/std.ts +++ b/plugs/core/std.ts @@ -1,10 +1,13 @@ import { asset, + codeWidget, datastore, + editor, mq, system, } from "@silverbulletmd/silverbullet/syscalls"; import type { FileMeta } from "@silverbulletmd/silverbullet/types"; +import { sleep } from "$lib/async.ts"; export async function listFiles(): Promise { return await asset.listFiles("core"); @@ -49,9 +52,11 @@ export async function init() { } // Iterate over the current file listing, check if any new files have been added, removed or modified const newListing = await listFiles(); + let anythingChanged = false; // First check for files that were removed for (const cachedFile of Object.keys(stdLibCache)) { if (!newListing.find((f) => f.name === cachedFile)) { + anythingChanged = true; console.log(`Clearing index for removed file ${cachedFile}`); await system.invokeFunction("index.clearDSIndex", cachedFile); delete stdLibCache[cachedFile]; @@ -64,7 +69,7 @@ export async function init() { // Check if file is new or modified compared to cache if (!stdLibCache[file.name] || stdLibCache[file.name] !== lastModified) { - // console.log(`Queuing for indexing ${file.name}`); + anythingChanged = true; await system.invokeFunction("index.clearDSIndex", file.name); await mq.send("indexQueue", file.name); stdLibCache[file.name] = lastModified; @@ -73,4 +78,21 @@ export async function init() { // Save updated cache await datastore.set(stdLibCacheKey, stdLibCache); + + // If anything changed and we're in sync mode, we can auto trigger reloading of the system after the index queue is processed + if (anythingChanged && !await system.getEnv()) { + // We're in sync mode + console.log("Waiting for index queue to be processed"); + let queueProcessed = false; + while (!queueProcessed) { + const stats = await mq.getQueueStats("indexQueue"); + if (stats.queued === 0 && stats.processing === 0) { + queueProcessed = true; + } + await sleep(100); + } + console.log("Index queue processed, reloading system"); + await editor.reloadConfigAndCommands(); + await codeWidget.refreshAll(); + } } diff --git a/web/client.ts b/web/client.ts index 605a272b..fc102de6 100644 --- a/web/client.ts +++ b/web/client.ts @@ -188,7 +188,9 @@ export class Client implements ConfigContainer { // Exclude all plug space primitives paths return !this.plugSpaceRemotePrimitives.isLikelyHandled(path) || // Except federated ones - path.startsWith("!"); + path.startsWith("!") || + // Also exclude Library/Std + path.startsWith("Library/Std"); }, ) : new NoSyncSyncService(this.space); @@ -565,6 +567,7 @@ export class Client implements ConfigContainer { }, ); } else { + // Not in sync mode localSpacePrimitives = new EventedSpacePrimitives( this.plugSpaceRemotePrimitives, this.eventHook,