mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-03 00:21:02 +01:00
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>
This commit is contained in:
parent
04a5a488b8
commit
bf76fde0c8
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user