From bf76fde0c8104de155f64022bf96c957bc5eb4ee Mon Sep 17 00:00:00 2001 From: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:56:35 +0530 Subject: [PATCH] Update duration regex for complete duration matching Refactor duration regex to match complete durations with units. Signed-off-by: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com> --- web/ui/module/codemirror-promql/src/complete/hybrid.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/web/ui/module/codemirror-promql/src/complete/hybrid.ts b/web/ui/module/codemirror-promql/src/complete/hybrid.ts index 429ac468dd..32d76956d8 100644 --- a/web/ui/module/codemirror-promql/src/complete/hybrid.ts +++ b/web/ui/module/codemirror-promql/src/complete/hybrid.ts @@ -166,17 +166,14 @@ function arrayToCompletionResult(data: Completion[], from: number, to: number, i } as CompletionResult; } -const durationUnitLabels = durationTerms - .map((term) => term.label) - .filter((label): label is string => typeof label === 'string') - .sort((a, b) => b.length - a.length); - -const durationWithUnitRegexp = new RegExp(`^\\d+(?:${durationUnitLabels.map((label) => escapeRegExp(label)).join('|')})$`); +// Matches complete duration with units (e.g., 5m, 30s, 1h, 500ms) +const durationWithUnitRegexp = new RegExp(`^\\d+(?:${durationTerms.map((term) => escapeRegExp(term.label)).join('|')})$`); function escapeRegExp(value: string): string { return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } +// Determines if a duration already has a complete time unit to prevent autocomplete insertion (issue #15452) function hasCompleteDurationUnit(state: EditorState, node: SyntaxNode): boolean { if (node.from >= node.to) { return false;