Code complete fixes and changelog

This commit is contained in:
Zef Hemel
2023-10-04 17:14:24 +02:00
parent 371932e085
commit d8797aa805
9 changed files with 115 additions and 121 deletions
+27 -4
View File
@@ -1,5 +1,5 @@
import { CompleteEvent } from "$sb/app_event.ts";
import { events } from "$sb/syscalls.ts";
import { events, language } from "$sb/syscalls.ts";
import {
AttributeCompleteEvent,
AttributeCompletion,
@@ -7,11 +7,12 @@ import {
export async function queryComplete(completeEvent: CompleteEvent) {
const fencedParent = completeEvent.parentNodes.find((node) =>
node === "FencedCode:query"
node.startsWith("FencedCode:query")
);
if (!fencedParent) {
return null;
}
// First let's try to match the query source
let querySourceMatch = /^\s*([\w\-_]*)$/.exec(
completeEvent.linePrefix,
);
@@ -41,8 +42,10 @@ export async function queryComplete(completeEvent: CompleteEvent) {
};
}
querySourceMatch = /^\s*([\w\-_]*)/.exec(
completeEvent.linePrefix,
// If that doesn't work, let's try to match other bits of the query
// For this we do need to find the query source, though, so let's look for it in fencedParent
querySourceMatch = /^[\n\r\s]*([\w\-_]+)/.exec(
fencedParent.slice("FencedCode:query".length),
);
const whereMatch =
/(where|order\s+by|and|or|select(\s+[\w\s,]+)?)\s+([\w\-_]*)$/
@@ -78,3 +81,23 @@ function attributeCompletionsToCMCompletion(
}),
);
}
export async function languageComplete(completeEvent: CompleteEvent) {
const languagePrefix = /^```(\w*)$/.exec(
completeEvent.linePrefix,
);
if (!languagePrefix) {
return null;
}
const allLanguages = await language.listLanguages();
return {
from: completeEvent.pos - languagePrefix[1].length,
options: allLanguages.map(
(lang) => ({
label: lang,
type: "language",
}),
),
};
}
+5
View File
@@ -15,6 +15,11 @@ functions:
events:
- editor:complete
languageComplete:
path: complete.ts:languageComplete
events:
- editor:complete
# Slash commands
insertQuery:
redirect: template.insertTemplateText