prometheus: monaco: autocomplete: offer function-names in functions (#41212)

This commit is contained in:
Gábor Farkas 2021-11-03 10:56:43 +01:00 committed by GitHub
parent 244e149c34
commit 72ae3235fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,6 +47,11 @@ const FUNCTION_COMPLETIONS: Completion[] = FUNCTIONS.map((f) => ({
documentation: f.documentation, documentation: f.documentation,
})); }));
async function getAllFunctionsAndMetricNamesCompletions(dataProvider: DataProvider): Promise<Completion[]> {
const metricNames = await getAllMetricNamesCompletions(dataProvider);
return [...FUNCTION_COMPLETIONS, ...metricNames];
}
const DURATION_COMPLETIONS: Completion[] = [ const DURATION_COMPLETIONS: Completion[] = [
'$__interval', '$__interval',
'$__range', '$__range',
@ -144,10 +149,9 @@ export async function getCompletions(situation: Situation, dataProvider: DataPro
case 'IN_DURATION': case 'IN_DURATION':
return DURATION_COMPLETIONS; return DURATION_COMPLETIONS;
case 'IN_FUNCTION': case 'IN_FUNCTION':
return getAllMetricNamesCompletions(dataProvider); return getAllFunctionsAndMetricNamesCompletions(dataProvider);
case 'AT_ROOT': { case 'AT_ROOT': {
const metricNames = await getAllMetricNamesCompletions(dataProvider); return getAllFunctionsAndMetricNamesCompletions(dataProvider);
return [...FUNCTION_COMPLETIONS, ...metricNames];
} }
case 'EMPTY': { case 'EMPTY': {
const metricNames = await getAllMetricNamesCompletions(dataProvider); const metricNames = await getAllMetricNamesCompletions(dataProvider);