Tons of work
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
declare global {
|
||||
function syscall(id: number, name: string, args: any[]): Promise<any>;
|
||||
var reqId: number;
|
||||
}
|
||||
|
||||
// This needs to be global, because this will be shared with all other functions in the same environment (worker-like)
|
||||
if (typeof self.reqId === "undefined") {
|
||||
self.reqId = 0;
|
||||
}
|
||||
|
||||
export async function syscall(name: string, ...args: any[]): Promise<any> {
|
||||
let reqId = Math.floor(Math.random() * 1000000);
|
||||
self.reqId++;
|
||||
// console.log("Syscall", name, reqId);
|
||||
return await self.syscall(reqId, name, args);
|
||||
// return new Promise((resolve, reject) => {
|
||||
// self.dispatchEvent(
|
||||
// new CustomEvent("syscall", {
|
||||
// detail: {
|
||||
// id: reqId,
|
||||
// name: name,
|
||||
// args: args,
|
||||
// callback: resolve,
|
||||
// },
|
||||
// })
|
||||
// );
|
||||
// });
|
||||
return await self.syscall(self.reqId, name, args);
|
||||
}
|
||||
|
||||
+24
-8
@@ -8,6 +8,7 @@ async function navigate(syntaxNode: any) {
|
||||
console.log("Attempting to navigate based on syntax node", syntaxNode);
|
||||
switch (syntaxNode.name) {
|
||||
case "WikiLinkPage":
|
||||
case "AtMention":
|
||||
await syscall("editor.navigate", syntaxNode.text);
|
||||
break;
|
||||
case "URL":
|
||||
@@ -35,16 +36,31 @@ export async function clickNavigate(event: ClickEvent) {
|
||||
}
|
||||
|
||||
export async function pageComplete() {
|
||||
let prefix = await syscall("editor.matchBefore", "\\[\\[[\\w\\s]*");
|
||||
let prefix = await syscall(
|
||||
"editor.matchBefore",
|
||||
"(\\[\\[[\\w\\s]*|@[\\w\\.]*)"
|
||||
);
|
||||
if (!prefix) {
|
||||
return null;
|
||||
}
|
||||
let allPages = await syscall("space.listPages");
|
||||
return {
|
||||
from: prefix.from + 2,
|
||||
options: allPages.map((pageMeta: any) => ({
|
||||
label: pageMeta.name,
|
||||
type: "page",
|
||||
})),
|
||||
};
|
||||
if (prefix.text[0] === "@") {
|
||||
return {
|
||||
from: prefix.from,
|
||||
options: allPages
|
||||
.filter((page) => page.name.startsWith(prefix.text))
|
||||
.map((pageMeta: any) => ({
|
||||
label: pageMeta.name,
|
||||
type: "page",
|
||||
})),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
from: prefix.from + 2,
|
||||
options: allPages.map((pageMeta: any) => ({
|
||||
label: pageMeta.name,
|
||||
type: "page",
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ import { pageLinkRegex } from "../../webapp/src/constant";
|
||||
import { syscall } from "./lib/syscall";
|
||||
|
||||
const wikilinkRegex = new RegExp(pageLinkRegex, "g");
|
||||
const atMentionRegex = /(@[A-Za-z\.]+)/g;
|
||||
|
||||
export async function indexLinks({ name, text }: IndexEvent) {
|
||||
let backLinks: { key: string; value: string }[] = [];
|
||||
// [[Style Links]]
|
||||
for (let match of text.matchAll(wikilinkRegex)) {
|
||||
let toPage = match[1];
|
||||
let pos = match.index!;
|
||||
@@ -14,6 +16,15 @@ export async function indexLinks({ name, text }: IndexEvent) {
|
||||
value: name,
|
||||
});
|
||||
}
|
||||
// @links
|
||||
for (let match of text.matchAll(atMentionRegex)) {
|
||||
let toPage = match[1];
|
||||
let pos = match.index!;
|
||||
backLinks.push({
|
||||
key: `pl:${toPage}:${pos}`,
|
||||
value: name,
|
||||
});
|
||||
}
|
||||
console.log("Found", backLinks.length, "wiki link(s)");
|
||||
// throw Error("Boom");
|
||||
await syscall("indexer.batchSet", name, backLinks);
|
||||
|
||||
Reference in New Issue
Block a user