Address PromQL autocomplete review feedback

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
This commit is contained in:
Asish Kumar 2026-05-13 12:03:05 +05:30
parent 7c6bab8c58
commit 0254e010b3
No known key found for this signature in database
GPG key ID: 0EF072B1E0BA6FBA
2 changed files with 8 additions and 3 deletions

View file

@ -1569,11 +1569,13 @@ describe('autocomplete promQL test', () => {
type: 'text',
},
{
label: '\\\\x2d',
label: '\\x2d',
apply: '\\\\x2d',
type: 'text',
},
{
label: 'quoted\\"value',
label: 'quoted"value',
apply: 'quoted\\"value',
type: 'text',
},
],

View file

@ -169,6 +169,9 @@ function arrayToCompletionResult(data: Completion[], from: number, to: number, i
}
function escapePromQLString(str: string): string {
// PromQL only evaluates escape sequences in single- and double-quoted strings.
// Backtick-quoted string completions are not handled separately today, so keep
// the inserted value escaped unconditionally.
return str.replace(/([\\"])/g, '\\$1');
}
@ -798,7 +801,7 @@ export class HybridComplete implements CompleteStrategy {
return result;
}
return this.prometheusClient.labelValues(context.labelName, context.metricName, context.matchers).then((labelValues: string[]) => {
return result.concat(labelValues.map((value) => ({ label: escapePromQLString(value), type: 'text' })));
return result.concat(labelValues.map((value) => ({ label: value, apply: escapePromQLString(value), type: 'text' })));
});
}
}