From a635f5451e2f16efcf09f5cc0679ba81e64ea683 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Sun, 25 Oct 2015 19:36:28 +0100 Subject: [PATCH] Don't autocomplete metrics in range specifications. --- web/blob/static/js/graph.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/web/blob/static/js/graph.js b/web/blob/static/js/graph.js index d1e66b8c4..dde8c610c 100644 --- a/web/blob/static/js/graph.js +++ b/web/blob/static/js/graph.js @@ -159,11 +159,11 @@ Prometheus.Graph.prototype.initialize = function() { }; // 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 -// section). +// like it could be a metric name (if it's not in a string, a label matchers +// section, or a range specification). function isPotentialMetric(str, pos) { var quote = null; - var inMatchers = false; + var inMatchersOrRange = false; for (var i = 0; i < pos; i++) { var ch = str[i]; @@ -185,7 +185,7 @@ function isPotentialMetric(str, pos) { break; } - // Ignore curly braces in strings. + // Ignore curly braces and square brackets in strings. if (quote) { continue; } @@ -193,15 +193,17 @@ function isPotentialMetric(str, pos) { // Track whether we are in curly braces (label matchers). switch (ch) { case "{": - inMatchers = true; + case "[": + inMatchersOrRange = true; break; case "}": - inMatchers = false; + case "]": + inMatchersOrRange = false; break; } } - return !inMatchers && quote === null; + return !inMatchersOrRange && quote === null; } // Returns the current word under the cursor position in $input.