prometheus: monaco: fix a corner-case with quotes (#41345)

This commit is contained in:
Gábor Farkas 2021-11-05 15:11:19 +01:00 committed by GitHub
parent 8a42fca485
commit c64997332d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -140,6 +140,10 @@ describe('situation', () => {
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"}', {
type: 'IN_LABEL_SELECTOR_WITH_LABEL_NAME',
labelName: 'job',

View File

@ -410,12 +410,29 @@ function resolveLabelKeysWithEquals(node: SyntaxNode, text: string, pos: number)
// for example `something{^}`
// there are some false positives that can end up in this situation, that we want
// to eliminate, for example: `something{a~^}`
// basically, if this subtree contains any error-node, we stop
// to eliminate:
// `something{a~^}` (if this subtree contains any error-node, we stop)
if (subTreeHasError(node)) {
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, [
['parent', 'VectorSelector'],
['firstChild', 'MetricIdentifier'],