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:
ADITYA TIWARI 2025-11-25 17:56:35 +05:30 committed by GitHub
parent 04a5a488b8
commit bf76fde0c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;