Refactoring

This commit is contained in:
Zef Hemel
2022-03-25 12:03:06 +01:00
parent b51730d33f
commit 08e6c3bad8
52 changed files with 796 additions and 326 deletions
-10
View File
@@ -45,12 +45,6 @@
"path": "/",
"handler": "endpointTest"
}
],
"crons": [
{
"cron": "*/15 * * * *",
"handler": "gitSnapshot"
}
]
},
"functions": {
@@ -96,10 +90,6 @@
"welcome": {
"path": "./server.ts:welcome",
"env": "server"
},
"gitSnapshot": {
"path": "./git.ts:commit",
"env": "server"
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { syscall } from "./lib/syscall";
import { syscall } from "../lib/syscall";
export async function insertToday() {
console.log("Inserting date");
-12
View File
@@ -1,12 +0,0 @@
import { syscall } from "./lib/syscall";
export async function commit() {
console.log("Snapshotting the current space to git");
await syscall("shell.run", "git", ["add", "./*.md"]);
try {
await syscall("shell.run", "git", ["commit", "-a", "-m", "Snapshot"]);
} catch (e) {
// We can ignore, this happens when there's no changes to commit
}
console.log("Done!");
}
-5
View File
@@ -1,5 +0,0 @@
declare global {
function syscall(name: string, ...args: any[]): Promise<any>;
}
export const syscall = self.syscall;
+1 -1
View File
@@ -1,4 +1,4 @@
import { syscall } from "./lib/syscall";
import { syscall } from "../lib/syscall";
export async function toggleH1() {
await togglePrefix("# ");
+10 -26
View File
@@ -1,5 +1,5 @@
import { ClickEvent } from "../../webapp/src/app_event";
import { syscall } from "./lib/syscall";
import { ClickEvent } from "../../webapp/app_event";
import { syscall } from "../lib/syscall";
async function navigate(syntaxNode: any) {
if (!syntaxNode) {
@@ -8,7 +8,6 @@ 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":
@@ -36,31 +35,16 @@ export async function clickNavigate(event: ClickEvent) {
}
export async function pageComplete() {
let prefix = await syscall(
"editor.matchBefore",
"(\\[\\[[\\w\\s]*|@[\\w\\.]*)"
);
let prefix = await syscall("editor.matchBefore", "\\[\\[[\\w\\s]*");
if (!prefix) {
return null;
}
let allPages = await syscall("space.listPages");
if (prefix.text[0] === "@") {
return {
from: prefix.from,
options: allPages
.filter((page: any) => 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",
})),
};
}
return {
from: prefix.from + 2,
options: allPages.map((pageMeta: any) => ({
label: pageMeta.name,
type: "page",
})),
};
}
+2 -11
View File
@@ -1,13 +1,13 @@
import { IndexEvent } from "../../webapp/app_event";
import { pageLinkRegex } from "../../webapp/constant";
import { syscall } from "./lib/syscall";
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!;
@@ -16,15 +16,6 @@ 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);
+1
View File
@@ -13,4 +13,5 @@ export function endpointTest(req: EndpointRequest): EndpointResponse {
export function welcome() {
console.log("Hello world!");
return "hi";
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { ClickEvent } from "../../webapp/src/app_event";
import { syscall } from "./lib/syscall";
import { syscall } from "../lib/syscall";
export async function taskToggle(event: ClickEvent) {
let syntaxNode = await syscall("editor.getSyntaxNodeAtPos", event.pos);
+1 -1
View File
@@ -1,4 +1,4 @@
import { syscall } from "./lib/syscall";
import { syscall } from "../lib/syscall";
function countWords(str: string): number {
var matches = str.match(/[\w\d\'\'-]+/gi);