mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 15:33:52 +01:00
Rename, fix autocomplete and singleline, etc...
This commit is contained in:
@@ -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',
|
||||
})),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user