Auto complete and lint fixes
This commit is contained in:
@@ -19,7 +19,6 @@ import { spaceluaApi } from "$common/space_lua/stdlib/space_lua.ts";
|
||||
import { mathApi } from "$common/space_lua/stdlib/math.ts";
|
||||
import { parse } from "$common/space_lua/parse.ts";
|
||||
import { evalStatement } from "$common/space_lua/eval.ts";
|
||||
import { parseRef } from "@silverbulletmd/silverbullet/lib/page_ref";
|
||||
|
||||
const printFunction = new LuaBuiltinFunction(async (_sf, ...args) => {
|
||||
console.log(
|
||||
|
||||
@@ -34,6 +34,15 @@ function template.new(templateStr)
|
||||
end
|
||||
end
|
||||
|
||||
function template.fromPage(name)
|
||||
local fm = index.extractFrontmatter(space.readPage(name), {
|
||||
removeFrontmatterSection = true,
|
||||
removeTags = true
|
||||
})
|
||||
|
||||
return template.new(fm.text)
|
||||
end
|
||||
|
||||
-- Creates a template-based slash command, keys for def are:
|
||||
-- name: name of the slash command
|
||||
-- description: description of the slash command
|
||||
|
||||
@@ -50,9 +50,7 @@ export async function pageComplete(completeEvent: CompleteEvent) {
|
||||
}));
|
||||
} // Let's try to be smart about the types of completions we're offering based on the context
|
||||
else if (
|
||||
completeEvent.parentNodes.find((node) =>
|
||||
node === "LuaDirective" || node.startsWith("FencedCode:space-lua")
|
||||
)
|
||||
completeEvent.parentNodes.find((node) => node === "Query")
|
||||
) {
|
||||
// Let's just disable page completion entirely in Lua directives and space-lua blocks
|
||||
return;
|
||||
|
||||
+1
-2
@@ -61,9 +61,8 @@ safeRun(async () => {
|
||||
if (!refreshing) {
|
||||
refreshing = true;
|
||||
console.log(
|
||||
"New service worker activated, reloading page to apply updates...",
|
||||
"New service worker activated, please reload to activate the new version.",
|
||||
);
|
||||
globalThis.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
decoratorStateField,
|
||||
invisibleDecoration,
|
||||
isCursorInRange,
|
||||
shouldRenderWidgets,
|
||||
} from "./util.ts";
|
||||
import type { Client } from "../client.ts";
|
||||
import { parse as parseLua } from "$common/space_lua/parse.ts";
|
||||
@@ -24,17 +23,48 @@ import { encodeRef } from "@silverbulletmd/silverbullet/lib/page_ref";
|
||||
import { resolveASTReference } from "$common/space_lua.ts";
|
||||
import { LuaWidget } from "./lua_widget.ts";
|
||||
import type { PageMeta } from "@silverbulletmd/silverbullet/types";
|
||||
import YAML from "js-yaml";
|
||||
|
||||
export function luaDirectivePlugin(client: Client) {
|
||||
return decoratorStateField((state: EditorState) => {
|
||||
const widgets: Range<Decoration>[] = [];
|
||||
if (!shouldRenderWidgets(client)) {
|
||||
console.info("Not rendering widgets");
|
||||
|
||||
let shouldRender = true;
|
||||
|
||||
// Don't render Lua directives of federated pages (security)
|
||||
if (client.currentPage.startsWith("!")) {
|
||||
return Decoration.set([]);
|
||||
}
|
||||
|
||||
syntaxTree(state).iterate({
|
||||
enter: (node) => {
|
||||
// Disable rendering of Lua directives in #meta/template pages
|
||||
// Either in frontmatter
|
||||
if (node.name === "FrontMatterCode") {
|
||||
const text = state.sliceDoc(node.from, node.to);
|
||||
try {
|
||||
const parsedFrontmatter = YAML.load(text);
|
||||
let tags = parsedFrontmatter.tags || [];
|
||||
if (typeof tags === "string") {
|
||||
tags = tags.split(/\s+|,\s*/);
|
||||
}
|
||||
if (tags.includes("meta/template")) {
|
||||
shouldRender = false;
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
// Or with a hash tag
|
||||
if (node.name === "Hashtag") {
|
||||
const text = state.sliceDoc(node.from, node.to);
|
||||
if (text === "#meta/template") {
|
||||
shouldRender = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.name !== "LuaDirective") {
|
||||
return;
|
||||
}
|
||||
@@ -108,6 +138,10 @@ export function luaDirectivePlugin(client: Client) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!shouldRender) {
|
||||
return Decoration.set([]);
|
||||
}
|
||||
|
||||
return Decoration.set(widgets, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
||||
ref = parseRef(ref);
|
||||
} else if (ref.kind === undefined) {
|
||||
// @ts-ignore: This is for legacy support
|
||||
locationRef.kind === "page";
|
||||
ref.kind === "page";
|
||||
}
|
||||
await client.navigate(ref, replaceState, newWindow);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user