Autocomplete, and more CM stuff!

This commit is contained in:
Gregory Schier
2023-02-28 22:54:54 -08:00
parent f568266c7f
commit 29d1f687d1
20 changed files with 220 additions and 178 deletions

View File

@@ -0,0 +1,34 @@
import type { CompletionContext } from '@codemirror/autocomplete';
const openTag = '${[ ';
const closeTag = ' ]}';
const variables = [
{ name: 'DOMAIN' },
{ name: 'BASE_URL' },
{ name: 'TOKEN' },
{ name: 'PROJECT_ID' },
];
export function myCompletions(context: CompletionContext) {
// console.log('COMPLETE', context);
const toStartOfName = context.matchBefore(/\w*/);
const toStartOfVariable = context.matchBefore(/\$\{.*/);
const toMatch = toStartOfVariable ?? toStartOfName ?? null;
if (toMatch === null) {
return null;
}
if (toMatch.from === toMatch.to && !context.explicit) {
return null;
}
return {
from: toMatch.from,
options: variables.map((v) => ({
label: `${openTag}${v.name}${closeTag}`,
type: 'variable',
})),
};
}