fix(flows): pebble autocompletion performance optimization (#11981)

closes #11881
This commit is contained in:
brian-mulier-p
2025-10-14 11:32:50 +02:00
committed by brian.mulier
parent 70ef82faba
commit 63f30f11ef
2 changed files with 11 additions and 21 deletions

View File

@@ -1,23 +1,22 @@
const maybeText = (allowSeparators: boolean) => "(?:\"[^\"]*\")|(?:'[^']*')|(?:(?:(?!\\}\\})" + (allowSeparators ? "[\\S\\n ]" : "[^~+,:\\n ]") + ")*)";
const maybeAnotherPebbleExpression = "(?:[\\n ]*\\{\\{[\\n ]*" + maybeText(true) + "[\\n ]*\\}\\}[\\n ]*)*";
const pebbleStart = "\\{\\{[\\n ]*";
const fieldWithoutDotCapture = "([^\\(\\)\\}:~+.\\n '\"]*)(?![^\\(\\)\\}\\n ])";
const dotAccessedFieldWithParentCapture = "([^\\(\\)\\}:~+\\n '\"]*)\\." + fieldWithoutDotCapture;
const maybeTextFollowedBySeparator = "(?:" + maybeText(false) + "[~+ ]+)*";
const paramKey = "[^\\n \\(\\)~+\\},:=]+";
const paramValue = "(?:(?:(?:\"[^\"]*\"?)|(?:'[^']*'?)|[^,)]))*";
const fieldWithoutDotCapture = "([^()}:~+.\\n '\"]*)(?![^()}\\n ])";
const dotAccessedFieldWithParentCapture = "([^()}:~+\\n '\"]*)\\." + fieldWithoutDotCapture;
const maybeTextFollowedBySeparator = "(?:" + maybeText(true) + "[\\n ]*(?:(?:[~+]+)|(?:\\}\\}[\\n ]*" + pebbleStart + "))[\\n ]*)*";
const paramKey = "[^\\n ()~+},:=]+";
const paramValue = "(?:(?:(?:\"[^\"]*\"?)|(?:'[^']*'?)|[^,)}]))*";
const maybeParams = "(" +
"(?:[\\n ]*" + paramKey + "[\\n ]*=[\\n ]*" + paramValue + "(?:[\\n ]*,[\\n ]*)?)+)?" +
"([^\\n \\(\\)~+\\},:=]*)?";
const functionWithMaybeParams = "([^\\n\\(\\)\\},:~ ]+)\\(" + maybeParams
"([^\\n ()~+},:=]*)?";
const functionWithMaybeParams = "([^\\n()},:~ ]+)\\(" + maybeParams
export default {
beforeSeparator: (additionalSeparators: string[] = []) => `([^\\}:\\n ${additionalSeparators.join("")}]*)`,
/** [fullMatch, dotForbiddenField] */
capturePebbleVarRoot: `${maybeAnotherPebbleExpression}${pebbleStart}${maybeTextFollowedBySeparator}${fieldWithoutDotCapture}`,
capturePebbleVarRoot: `${pebbleStart}${maybeTextFollowedBySeparator}${fieldWithoutDotCapture}`,
/** [fullMatch, parentFieldMaybeIncludingDots, childField] */
capturePebbleVarParent: `${maybeAnotherPebbleExpression}${pebbleStart}${maybeTextFollowedBySeparator}${dotAccessedFieldWithParentCapture}`,
capturePebbleVarParent: `${pebbleStart}${maybeTextFollowedBySeparator}${dotAccessedFieldWithParentCapture}`,
/** [fullMatch, functionName, textBetweenParenthesis, maybeTypedWordStart] */
capturePebbleFunction: `${maybeAnotherPebbleExpression}${pebbleStart}${maybeTextFollowedBySeparator}${functionWithMaybeParams}`,
capturePebbleFunction: `${pebbleStart}${maybeTextFollowedBySeparator}${functionWithMaybeParams}`,
captureStringValue: "^[\"']([^\"']+)[\"']$"
}

View File

@@ -109,16 +109,7 @@ tasks:
"\\")) | (.key + \\"->\\" + .value)"
}} {{myFunc(my-param_1='value1', my-param_2="value2", myK`
expect([...(regex.exec(shouldMatchLastFunction) ?? [])]).toEqual([
`id: breaking-ui
namespace: io.kestra.blx
description: "Upload multiple files to s3 sequentially"
tasks:
- id: placeholder
type: io.kestra.plugin.core.log.Log
message: |-
{{
`{{
"to_entries[] | select(.key | startswith(\\"" +
inputs.selector +
"\\")) | (.key + \\"->\\" + .value)"