mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-08 19:11:02 +01:00
Merge pull request #17602 from ADITYATIWARI342005/fix/closingAutocomplete
[BUGFIX] UI: Fixed codemirror-promql incorrectly showing label completion suggestions
This commit is contained in:
commit
fb47037435
@ -299,6 +299,12 @@ describe('analyzeCompletion test', () => {
|
|||||||
pos: 33, // cursor is between the bracket after the comma
|
pos: 33, // cursor is between the bracket after the comma
|
||||||
expectedContext: [{ kind: ContextKind.LabelName, metricName: 'metric_name' }],
|
expectedContext: [{ kind: ContextKind.LabelName, metricName: 'metric_name' }],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'no label suggestions after closing matcher',
|
||||||
|
expr: 'up{job="prometheus"}',
|
||||||
|
pos: 20, // cursor is right after the closing curly bracket
|
||||||
|
expectedContext: [],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'continue autocomplete labelName that defined a metric',
|
title: 'continue autocomplete labelName that defined a metric',
|
||||||
expr: '{myL}',
|
expr: '{myL}',
|
||||||
|
|||||||
@ -400,12 +400,18 @@ export function analyzeCompletion(state: EditorState, node: SyntaxNode, pos: num
|
|||||||
// so we have or to autocomplete any kind of labelName or to autocomplete only the labelName associated to the metric
|
// so we have or to autocomplete any kind of labelName or to autocomplete only the labelName associated to the metric
|
||||||
result.push({ kind: ContextKind.LabelName, metricName: getMetricNameInGroupBy(node, state) });
|
result.push({ kind: ContextKind.LabelName, metricName: getMetricNameInGroupBy(node, state) });
|
||||||
break;
|
break;
|
||||||
case LabelMatchers:
|
case LabelMatchers: {
|
||||||
|
if (pos >= node.to) {
|
||||||
|
// Cursor is outside of the label matcher block (e.g. right after `}`),
|
||||||
|
// so don't offer label-related completions anymore.
|
||||||
|
break;
|
||||||
|
}
|
||||||
// In that case we are in the given situation:
|
// In that case we are in the given situation:
|
||||||
// metric_name{} or {}
|
// metric_name{} or {}
|
||||||
// so we have or to autocomplete any kind of labelName or to autocomplete only the labelName associated to the metric
|
// so we have or to autocomplete any kind of labelName or to autocomplete only the labelName associated to the metric
|
||||||
result.push({ kind: ContextKind.LabelName, metricName: getMetricNameInVectorSelector(node, state) });
|
result.push({ kind: ContextKind.LabelName, metricName: getMetricNameInVectorSelector(node, state) });
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case LabelName:
|
case LabelName:
|
||||||
if (node.parent?.type.id === GroupingLabels) {
|
if (node.parent?.type.id === GroupingLabels) {
|
||||||
// In this case we are in the given situation:
|
// In this case we are in the given situation:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user