@fc-components/monaco-editor 0.1.27 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -346,6 +346,7 @@ for (var _i = 0, aggregations_1 = aggregations; _i < aggregations_1.length; _i++
346
346
  // PromQL vector matching + the by and without clauses
347
347
  // (https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching)
348
348
  var vectorMatching = ['on', 'ignoring', 'group_right', 'group_left', 'by', 'without'];
349
+ var cteKeywords = ['with'];
349
350
  // Produce a regex matching elements : (elt1|elt2|...)
350
351
  var vectorMatchingRegex = '(' + /*#__PURE__*/vectorMatching.reduce(function (prev, curr) {
351
352
  return prev + '|' + curr;
@@ -357,7 +358,7 @@ var operators = ['+', '-', '*', '/', '%', '^', '==', '!=', '>', '<', '>=', '<=',
357
358
  // (https://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier)
358
359
  var offsetModifier = ['offset'];
359
360
  // Merging all the keywords in one list
360
- var keywords = /*#__PURE__*/aggregations.concat(functions).concat(aggregationsOverTime).concat(vectorMatching).concat(offsetModifier);
361
+ var keywords = /*#__PURE__*/aggregations.concat(functions).concat(aggregationsOverTime).concat(vectorMatching).concat(offsetModifier).concat(cteKeywords);
361
362
  // noinspection JSUnusedGlobalSymbols
362
363
  var language = {
363
364
  ignoreCase: false,
@@ -1295,6 +1296,15 @@ var RESOLVERS = [{
1295
1296
  }, {
1296
1297
  path: [lezerMetricsql.GroupingLabels],
1297
1298
  fun: resolveLabelsForGrouping
1299
+ }, {
1300
+ path: [lezerMetricsql.WithExpr],
1301
+ fun: resolveWithExpr
1302
+ }, {
1303
+ path: [lezerMetricsql.WithExpr, lezerMetricsql.PromQL],
1304
+ fun: resolveWithExpr
1305
+ }, {
1306
+ path: [lezerMetricsql.WithAssignment, lezerMetricsql.WithExpr],
1307
+ fun: resolveWithExpr
1298
1308
  }];
1299
1309
  var LABEL_OP_MAP = /*#__PURE__*/new Map([[lezerMetricsql.EqlSingle, '='], [lezerMetricsql.EqlRegex, '=~'], [lezerMetricsql.Neq, '!='], [lezerMetricsql.NeqRegex, '!~']]);
1300
1310
  function getLabelOp(opNode) {
@@ -1467,6 +1477,25 @@ function resolveInFunction() {
1467
1477
  type: 'IN_FUNCTION'
1468
1478
  };
1469
1479
  }
1480
+ function resolveWithExpr(node, text, pos) {
1481
+ // Find the containing WithExpr node (node may be a WithAssignment child)
1482
+ var withExprNode = node.type.id === lezerMetricsql.WithExpr ? node : node.parent;
1483
+ while (withExprNode && withExprNode.type.id !== lezerMetricsql.WithExpr) {
1484
+ withExprNode = withExprNode.parent;
1485
+ }
1486
+ if (!withExprNode) return null;
1487
+ // Only return IN_WITH_BODY when cursor is in the body expression (after the closing ')')
1488
+ var children = getNodeChildren(withExprNode);
1489
+ var closeParen = children.find(function (c) {
1490
+ return getNodeText(c, text) === ')';
1491
+ });
1492
+ if (closeParen && pos > closeParen.to) {
1493
+ return {
1494
+ type: 'IN_WITH_BODY'
1495
+ };
1496
+ }
1497
+ return null;
1498
+ }
1470
1499
  function resolveDurations() {
1471
1500
  return {
1472
1501
  type: 'IN_DURATION'
@@ -1576,6 +1605,25 @@ function getErrorNode(tree, pos) {
1576
1605
  }
1577
1606
  return null;
1578
1607
  }
1608
+ function findMatchingParen(text, openPos) {
1609
+ var depth = 0;
1610
+ for (var i = openPos; i < text.length; i++) {
1611
+ if (text[i] === '(') depth++;
1612
+ if (text[i] === ')') {
1613
+ depth--;
1614
+ if (depth === 0) return i;
1615
+ }
1616
+ }
1617
+ return -1;
1618
+ }
1619
+ function isInWithBody(text, pos) {
1620
+ var withMatch = text.match(/^with\s*\(/i);
1621
+ if (!withMatch) return false;
1622
+ var openParenPos = withMatch[0].length - 1;
1623
+ var closeParenPos = findMatchingParen(text, openParenPos);
1624
+ if (closeParenPos === -1) return false;
1625
+ return pos > closeParenPos;
1626
+ }
1579
1627
  function getSituation(text, pos) {
1580
1628
  // there is a special-case when we are at the start of writing text,
1581
1629
  // so we handle that case first
@@ -1584,6 +1632,12 @@ function getSituation(text, pos) {
1584
1632
  type: 'EMPTY'
1585
1633
  };
1586
1634
  }
1635
+ // text-based check for with body (fallback until grammar supports WithExpr)
1636
+ if (isInWithBody(text, pos)) {
1637
+ return {
1638
+ type: 'IN_WITH_BODY'
1639
+ };
1640
+ }
1587
1641
  /**
1588
1642
  PromQL
1589
1643
  Expr
@@ -1666,12 +1720,19 @@ function _getAllFunctionsAndMetricNamesCompletions() {
1666
1720
  while (1) switch (_context.n) {
1667
1721
  case 0:
1668
1722
  metricNames = getAllMetricNamesCompletions(dataProvider);
1669
- return _context.a(2, [].concat(FUNCTION_COMPLETIONS, metricNames));
1723
+ return _context.a(2, [CTE_KEYWORD_COMPLETION].concat(FUNCTION_COMPLETIONS, metricNames));
1670
1724
  }
1671
1725
  }, _callee);
1672
1726
  }));
1673
1727
  return _getAllFunctionsAndMetricNamesCompletions.apply(this, arguments);
1674
1728
  }
1729
+ var CTE_KEYWORD_COMPLETION = {
1730
+ type: 'FUNCTION',
1731
+ label: 'with',
1732
+ insertText: 'with (',
1733
+ detail: 'with (cte_name = expr, ...) expr',
1734
+ documentation: 'Define Common Table Expressions (CTEs) for use in the query. MetricsQL extension.'
1735
+ };
1675
1736
  var DURATION_COMPLETIONS = /*#__PURE__*/['1m', '5m', '10m', '30m', '1h', '1d'].map(function (text) {
1676
1737
  return {
1677
1738
  type: 'DURATION',
@@ -1913,6 +1974,7 @@ function getCompletions(situation, dataProvider) {
1913
1974
  return Promise.resolve(DURATION_COMPLETIONS);
1914
1975
  case 'IN_FUNCTION':
1915
1976
  return getAllFunctionsAndMetricNamesCompletions(dataProvider);
1977
+ case 'IN_WITH_BODY':
1916
1978
  case 'AT_ROOT':
1917
1979
  {
1918
1980
  return getAllFunctionsAndMetricNamesCompletions(dataProvider);
@@ -1921,7 +1983,7 @@ function getCompletions(situation, dataProvider) {
1921
1983
  {
1922
1984
  var metricNames = getAllMetricNamesCompletions(dataProvider);
1923
1985
  var historyCompletions = getAllHistoryCompletions();
1924
- return Promise.resolve([].concat(historyCompletions, FUNCTION_COMPLETIONS, metricNames));
1986
+ return Promise.resolve([].concat(historyCompletions, [CTE_KEYWORD_COMPLETION], FUNCTION_COMPLETIONS, metricNames));
1925
1987
  }
1926
1988
  case 'IN_LABEL_SELECTOR_NO_LABEL_NAME':
1927
1989
  return getLabelNamesForSelectorCompletions(situation.metricName, situation.hasOperator, situation.otherLabels, dataProvider);