mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
prometheus: monaco: fix a corner-case with quotes (#41345)
This commit is contained in:
parent
8a42fca485
commit
c64997332d
@ -140,6 +140,10 @@ describe('situation', () => {
|
|||||||
otherLabels: [{ name: 'job', value: 'j1', op: '=' }],
|
otherLabels: [{ name: 'job', value: 'j1', op: '=' }],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assertSituation('something{job="j1"^}', null);
|
||||||
|
assertSituation('something{job="j1" ^ }', null);
|
||||||
|
assertSituation('something{job="j1" ^ , }', null);
|
||||||
|
|
||||||
assertSituation('{job=^,host="h1"}', {
|
assertSituation('{job=^,host="h1"}', {
|
||||||
type: 'IN_LABEL_SELECTOR_WITH_LABEL_NAME',
|
type: 'IN_LABEL_SELECTOR_WITH_LABEL_NAME',
|
||||||
labelName: 'job',
|
labelName: 'job',
|
||||||
|
@ -410,12 +410,29 @@ function resolveLabelKeysWithEquals(node: SyntaxNode, text: string, pos: number)
|
|||||||
// for example `something{^}`
|
// for example `something{^}`
|
||||||
|
|
||||||
// there are some false positives that can end up in this situation, that we want
|
// there are some false positives that can end up in this situation, that we want
|
||||||
// to eliminate, for example: `something{a~^}`
|
// to eliminate:
|
||||||
// basically, if this subtree contains any error-node, we stop
|
// `something{a~^}` (if this subtree contains any error-node, we stop)
|
||||||
if (subTreeHasError(node)) {
|
if (subTreeHasError(node)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// next false positive:
|
||||||
|
// `something{a="1"^}`
|
||||||
|
const child = walk(node, [['firstChild', 'LabelMatchList']]);
|
||||||
|
if (child !== null) {
|
||||||
|
// means the label-matching part contains at least one label already.
|
||||||
|
//
|
||||||
|
// in this case, we will need to have a `,` character at the end,
|
||||||
|
// to be able to suggest adding the next label.
|
||||||
|
// the area between the end-of-the-child-node and the cursor-pos
|
||||||
|
// must contain a `,` in this case.
|
||||||
|
const textToCheck = text.slice(child.to, pos);
|
||||||
|
|
||||||
|
if (!textToCheck.includes(',')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const metricNameNode = walk(node, [
|
const metricNameNode = walk(node, [
|
||||||
['parent', 'VectorSelector'],
|
['parent', 'VectorSelector'],
|
||||||
['firstChild', 'MetricIdentifier'],
|
['firstChild', 'MetricIdentifier'],
|
||||||
|
Loading…
Reference in New Issue
Block a user