Commit e98254e1 by Mitsuhiro Tanda Committed by Torkel Ödegaard

show only label name in label matcher (#9167)

parent 4446e951
......@@ -49,15 +49,42 @@ var PrometheusHighlightRules = function() {
regex : "\\+|\\-|\\*|\\/|%|\\^|=|==|!=|<=|>=|<|>|=\\~|!\\~"
}, {
token : "paren.lparen",
regex : "[[({]"
regex : "[[(]"
}, {
token : "paren.lparen",
regex : "{",
next : "start-label-matcher"
}, {
token : "paren.rparen",
regex : "[\\])]"
}, {
token : "paren.rparen",
regex : "[\\])}]"
regex : "}"
}, {
token : "text",
regex : "\\s+"
} ],
"start-label-matcher" : [ {
token : "label.name",
regex : '[a-zA-Z_][a-zA-Z0-9_]*'
}, {
token : "label.matching_operator",
regex : '=|!=|=~|!~'
}, {
token : "label.value",
regex : '"[^"]*"|\'[^\']*\''
}, {
token : "label.matching_delimiter",
regex : ",",
push : 'start-label-matcher'
}, {
token : "label.matching_end",
regex : "}",
next : "start"
} ]
};
this.normalizeRules();
};
oop.inherits(PrometheusHighlightRules, TextHighlightRules);
......@@ -373,6 +400,11 @@ var PrometheusCompletions = function() {};
(function() {
this.getCompletions = function(state, session, pos, prefix, callback) {
let token = session.getTokenAt(pos.row, pos.column);
if (token.type === 'label.name' || token.type === 'label.value') {
return callback(null, []);
}
var completions = keyWordsCompletions.concat(functionsCompletions);
callback(null, completions);
};
......
......@@ -9,6 +9,24 @@ export class PromCompleter {
}
getCompletions(editor, session, pos, prefix, callback) {
let token = session.getTokenAt(pos.row, pos.column);
switch (token.type) {
case 'label.name':
callback(null, ['instance', 'job'].map(function (key) {
return {
caption: key,
value: key,
meta: "label name",
score: Number.MAX_VALUE
};
}));
return;
case 'label.value':
callback(null, []);
return;
}
if (prefix === '[') {
var vectors = [];
for (let unit of ['s', 'm', 'h']) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment