Rename, fix autocomplete and singleline, etc...

This commit is contained in:
Gregory Schier
2023-03-02 10:42:43 -08:00
parent 43bc346a2b
commit 59967374c5
27 changed files with 128 additions and 114 deletions

View File

@@ -8,25 +8,30 @@ const variables = [
{ name: 'BASE_URL' },
{ name: 'TOKEN' },
{ name: 'PROJECT_ID' },
{ name: 'DUMMY' },
{ name: 'DUMMY_2' },
];
export function myCompletions(context: CompletionContext) {
const toStartOfName = context.matchBefore(/\w*/);
const toStartOfVariable = context.matchBefore(/\$\{.*/);
const toStartOfName = context.explicit ? context.matchBefore(/\w*/) : context.matchBefore(/\w+/);
const toStartOfVariable = context.matchBefore(/\$\{?\[?\s*\w*/);
const toMatch = toStartOfVariable ?? toStartOfName ?? null;
if (toMatch === null) {
return null;
}
if (toMatch.from === toMatch.to && !context.explicit) {
// Match a minimum of two characters when typing a variable ${[...]} to prevent it
// from opening on "$"
if (toStartOfVariable !== null && toMatch.to - toMatch.from < 2 && !context.explicit) {
return null;
}
return {
from: toMatch.from,
options: variables.map((v) => ({
label: `${openTag}${v.name}${closeTag}`,
label: toStartOfVariable ? `${openTag}${v.name}${closeTag}` : v.name,
apply: `${openTag}${v.name}${closeTag}`,
type: 'variable',
})),
};