Official 1Password Template Function (#305)

This commit is contained in:
Gregory Schier
2025-11-22 06:08:13 -08:00
committed by GitHub
parent 43a7132014
commit 2bac610efe
20 changed files with 1440 additions and 142 deletions

View File

@@ -20,27 +20,18 @@ export function useTemplateFunctionCompletionOptions(
if (!enabled) {
return [];
}
return (
templateFunctions.map((fn) => {
const NUM_ARGS = 2;
const argsWithName = fn.args.filter((a) => 'name' in a);
const shortArgs =
argsWithName
.slice(0, NUM_ARGS)
.map((a) => a.name)
.join(', ') + (fn.args.length > NUM_ARGS ? ', …' : '');
return {
name: fn.name,
aliases: fn.aliases,
type: 'function',
description: fn.description,
args: argsWithName.map((a) => ({ name: a.name })),
value: null,
label: `${fn.name}(${shortArgs})`,
onClick: (rawTag: string, startPos: number) => onClick(fn, rawTag, startPos),
};
}) ?? []
);
return templateFunctions.map((fn) => {
const argsLabel = fn.args.length > 0 ? '…' : '';
const fn2: TwigCompletionOption = {
type: 'function',
onClick: (rawTag: string, startPos: number) => onClick(fn, rawTag, startPos),
label: `${fn.name}(${argsLabel})`,
invalid: false,
value: null,
...fn,
};
return fn2;
});
}, [enabled, onClick, templateFunctions]);
}