Merge pull request #1181 from prometheus/fix-range-autocomplete

Don't autocomplete metrics in range specifications.
pull/1183/head
Fabian Reinartz 9 years ago
commit cae354c6a7

@ -159,11 +159,11 @@ Prometheus.Graph.prototype.initialize = function() {
}; };
// Returns true if the character at "pos" in the expression string "str" looks // Returns true if the character at "pos" in the expression string "str" looks
// like it could be a metric name (if it's not in a string or a label matchers // like it could be a metric name (if it's not in a string, a label matchers
// section). // section, or a range specification).
function isPotentialMetric(str, pos) { function isPotentialMetric(str, pos) {
var quote = null; var quote = null;
var inMatchers = false; var inMatchersOrRange = false;
for (var i = 0; i < pos; i++) { for (var i = 0; i < pos; i++) {
var ch = str[i]; var ch = str[i];
@ -185,7 +185,7 @@ function isPotentialMetric(str, pos) {
break; break;
} }
// Ignore curly braces in strings. // Ignore curly braces and square brackets in strings.
if (quote) { if (quote) {
continue; continue;
} }
@ -193,15 +193,17 @@ function isPotentialMetric(str, pos) {
// Track whether we are in curly braces (label matchers). // Track whether we are in curly braces (label matchers).
switch (ch) { switch (ch) {
case "{": case "{":
inMatchers = true; case "[":
inMatchersOrRange = true;
break; break;
case "}": case "}":
inMatchers = false; case "]":
inMatchersOrRange = false;
break; break;
} }
} }
return !inMatchers && quote === null; return !inMatchersOrRange && quote === null;
} }
// Returns the current word under the cursor position in $input. // Returns the current word under the cursor position in $input.

Loading…
Cancel
Save