@fc-components/monaco-editor 0.1.24 → 0.1.25
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.
- package/dist/monaco-editor.cjs.development.js +122 -10
- package/dist/monaco-editor.cjs.development.js.map +1 -1
- package/dist/monaco-editor.cjs.production.min.js +1 -1
- package/dist/monaco-editor.cjs.production.min.js.map +1 -1
- package/dist/monaco-editor.esm.js +123 -11
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/situation.d.ts +1 -0
- package/package.json +1 -1
- package/src/promql/completion/completions.ts +3 -3
- package/src/promql/completion/situation.ts +116 -1
- package/src/promql/index.tsx +24 -0
|
@@ -1254,11 +1254,29 @@ function isPathMatch(resolverPath, cursorPath) {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
var ERROR_NODE_NAME = 0; // this is used as error-id
|
|
1256
1256
|
var RESOLVERS = [{
|
|
1257
|
+
path: [lezerMetricsql.LabelName, lezerMetricsql.UnquotedLabelMatcher],
|
|
1258
|
+
fun: resolveLabelName
|
|
1259
|
+
}, {
|
|
1260
|
+
path: [lezerMetricsql.UnquotedLabelMatcher, lezerMetricsql.LabelMatchers],
|
|
1261
|
+
fun: resolveLabelName
|
|
1262
|
+
}, {
|
|
1257
1263
|
path: [lezerMetricsql.LabelMatchers, lezerMetricsql.VectorSelector],
|
|
1258
1264
|
fun: resolveLabelKeysWithEquals
|
|
1265
|
+
}, {
|
|
1266
|
+
path: [lezerMetricsql.LabelMatchers, lezerMetricsql.VectorSelector, lezerMetricsql.PromQL],
|
|
1267
|
+
fun: resolveLabelKeysWithEquals
|
|
1259
1268
|
}, {
|
|
1260
1269
|
path: [lezerMetricsql.PromQL],
|
|
1261
1270
|
fun: resolveTopLevel
|
|
1271
|
+
}, {
|
|
1272
|
+
path: [lezerMetricsql.VectorSelector, lezerMetricsql.PromQL],
|
|
1273
|
+
fun: resolveTopLevel
|
|
1274
|
+
}, {
|
|
1275
|
+
path: [lezerMetricsql.Identifier, lezerMetricsql.VectorSelector],
|
|
1276
|
+
fun: resolveTopLevel
|
|
1277
|
+
}, {
|
|
1278
|
+
path: [lezerMetricsql.Identifier, lezerMetricsql.VectorSelector, lezerMetricsql.PromQL],
|
|
1279
|
+
fun: resolveTopLevel
|
|
1262
1280
|
}, {
|
|
1263
1281
|
path: [lezerMetricsql.FunctionCallBody],
|
|
1264
1282
|
fun: resolveInFunction
|
|
@@ -1270,7 +1288,7 @@ var RESOLVERS = [{
|
|
|
1270
1288
|
fun: resolveTopLevel
|
|
1271
1289
|
}, {
|
|
1272
1290
|
path: [ERROR_NODE_NAME, lezerMetricsql.UnquotedLabelMatcher],
|
|
1273
|
-
fun:
|
|
1291
|
+
fun: resolveErrorInLabelMatcher
|
|
1274
1292
|
}, {
|
|
1275
1293
|
path: [ERROR_NODE_NAME, lezerMetricsql.NumberDurationLiteralInDurationContext, lezerMetricsql.MatrixSelector],
|
|
1276
1294
|
fun: resolveDurations
|
|
@@ -1412,6 +1430,27 @@ function resolveLabelMatcher(node, text, _pos) {
|
|
|
1412
1430
|
otherLabels: otherLabels
|
|
1413
1431
|
};
|
|
1414
1432
|
}
|
|
1433
|
+
function resolveErrorInLabelMatcher(node, text, pos) {
|
|
1434
|
+
// 处理错误节点在 UnquotedLabelMatcher 中的情况
|
|
1435
|
+
// 需要判断是删除值还是删除名称
|
|
1436
|
+
var parent = walk(node, [['parent', lezerMetricsql.UnquotedLabelMatcher]]);
|
|
1437
|
+
if (parent === null) {
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
var labelNameNode = walk(parent, [['firstChild', lezerMetricsql.LabelName]]);
|
|
1441
|
+
// 情况1: 有完整的标签名 -> 提示 label value
|
|
1442
|
+
if (labelNameNode !== null) {
|
|
1443
|
+
// 检查是否有 MatchOp(=, =~, !=, !~)
|
|
1444
|
+
var hasMatchOp = walk(labelNameNode, [['nextSibling', lezerMetricsql.MatchOp]]) !== null;
|
|
1445
|
+
if (hasMatchOp) {
|
|
1446
|
+
// 这是值场景,使用 resolveLabelMatcher 的逻辑
|
|
1447
|
+
return resolveLabelMatcher(node, text);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
// 情况2: 没有完整的标签名或没有 MatchOp -> 提示 label name
|
|
1451
|
+
// 使用 resolveLabelName 的逻辑
|
|
1452
|
+
return resolveLabelName(parent, text, pos);
|
|
1453
|
+
}
|
|
1415
1454
|
function resolveTopLevel() {
|
|
1416
1455
|
return {
|
|
1417
1456
|
type: 'AT_ROOT'
|
|
@@ -1427,6 +1466,55 @@ function resolveDurations() {
|
|
|
1427
1466
|
type: 'IN_DURATION'
|
|
1428
1467
|
};
|
|
1429
1468
|
}
|
|
1469
|
+
function resolveLabelName(node, text, pos) {
|
|
1470
|
+
var labelMatcherNode = node;
|
|
1471
|
+
// 如果节点是错误节点,尝试找到其父节点 UnquotedLabelMatcher
|
|
1472
|
+
if (node.type.isError) {
|
|
1473
|
+
var parent = node.parent;
|
|
1474
|
+
if (parent !== null && parent.type.id === lezerMetricsql.UnquotedLabelMatcher) {
|
|
1475
|
+
labelMatcherNode = parent;
|
|
1476
|
+
} else {
|
|
1477
|
+
return null;
|
|
1478
|
+
}
|
|
1479
|
+
} else if (node.type.id === lezerMetricsql.LabelName) {
|
|
1480
|
+
labelMatcherNode = walk(node, [['parent', lezerMetricsql.UnquotedLabelMatcher]]);
|
|
1481
|
+
}
|
|
1482
|
+
if (labelMatcherNode === null || labelMatcherNode.type.id !== lezerMetricsql.UnquotedLabelMatcher) {
|
|
1483
|
+
return null;
|
|
1484
|
+
}
|
|
1485
|
+
var labelNameNode = walk(labelMatcherNode, [['firstChild', lezerMetricsql.LabelName]]);
|
|
1486
|
+
if (labelNameNode === null) {
|
|
1487
|
+
return null;
|
|
1488
|
+
}
|
|
1489
|
+
if (pos > labelNameNode.to) {
|
|
1490
|
+
return null;
|
|
1491
|
+
}
|
|
1492
|
+
var labelMatchersNode = walk(labelMatcherNode, [['parent', lezerMetricsql.LabelMatchers]]);
|
|
1493
|
+
if (labelMatchersNode === null) {
|
|
1494
|
+
return null;
|
|
1495
|
+
}
|
|
1496
|
+
var currentLabelName = getNodeText(labelNameNode, text);
|
|
1497
|
+
var allLabels = getLabels(labelMatchersNode, text);
|
|
1498
|
+
var otherLabels = allLabels.filter(function (label) {
|
|
1499
|
+
return label.name !== currentLabelName;
|
|
1500
|
+
});
|
|
1501
|
+
var hasOperator = walk(labelNameNode, [['nextSibling', lezerMetricsql.MatchOp]]) !== null;
|
|
1502
|
+
var metricNameNode = walk(labelMatchersNode, [['parent', lezerMetricsql.VectorSelector], ['firstChild', lezerMetricsql.Identifier]]);
|
|
1503
|
+
if (metricNameNode === null) {
|
|
1504
|
+
return {
|
|
1505
|
+
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1506
|
+
otherLabels: otherLabels,
|
|
1507
|
+
hasOperator: hasOperator
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
var metricName = getNodeText(metricNameNode, text);
|
|
1511
|
+
return {
|
|
1512
|
+
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1513
|
+
metricName: metricName,
|
|
1514
|
+
otherLabels: otherLabels,
|
|
1515
|
+
hasOperator: hasOperator
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1430
1518
|
function resolveLabelKeysWithEquals(node, text, pos) {
|
|
1431
1519
|
// next false positive:
|
|
1432
1520
|
// `something{a="1"^}`
|
|
@@ -1449,14 +1537,16 @@ function resolveLabelKeysWithEquals(node, text, pos) {
|
|
|
1449
1537
|
// we are probably in a situation without a metric name.
|
|
1450
1538
|
return {
|
|
1451
1539
|
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1452
|
-
otherLabels: otherLabels
|
|
1540
|
+
otherLabels: otherLabels,
|
|
1541
|
+
hasOperator: false
|
|
1453
1542
|
};
|
|
1454
1543
|
}
|
|
1455
1544
|
var metricName = getNodeText(metricNameNode, text);
|
|
1456
1545
|
return {
|
|
1457
1546
|
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1458
1547
|
metricName: metricName,
|
|
1459
|
-
otherLabels: otherLabels
|
|
1548
|
+
otherLabels: otherLabels,
|
|
1549
|
+
hasOperator: false
|
|
1460
1550
|
};
|
|
1461
1551
|
}
|
|
1462
1552
|
// we find the first error-node in the tree that is at the cursor-position.
|
|
@@ -1504,8 +1594,10 @@ function getSituation(text, pos) {
|
|
|
1504
1594
|
var cur = maybeErrorNode != null ? maybeErrorNode.cursor() : tree.cursorAt(pos);
|
|
1505
1595
|
var currentNode = cur.node;
|
|
1506
1596
|
var ids = [cur.type.id];
|
|
1597
|
+
// const names = [cur.type.name];
|
|
1507
1598
|
while (cur.parent()) {
|
|
1508
1599
|
ids.push(cur.type.id);
|
|
1600
|
+
// names.push(cur.type.name);
|
|
1509
1601
|
}
|
|
1510
1602
|
for (var _iterator3 = _createForOfIteratorHelperLoose(RESOLVERS), _step3; !(_step3 = _iterator3()).done;) {
|
|
1511
1603
|
var resolver = _step3.value;
|
|
@@ -1688,21 +1780,21 @@ function _getLabelNamesForCompletions() {
|
|
|
1688
1780
|
}));
|
|
1689
1781
|
return _getLabelNamesForCompletions.apply(this, arguments);
|
|
1690
1782
|
}
|
|
1691
|
-
function getLabelNamesForSelectorCompletions(_x0, _x1, _x10) {
|
|
1783
|
+
function getLabelNamesForSelectorCompletions(_x0, _x1, _x10, _x11) {
|
|
1692
1784
|
return _getLabelNamesForSelectorCompletions.apply(this, arguments);
|
|
1693
1785
|
}
|
|
1694
1786
|
function _getLabelNamesForSelectorCompletions() {
|
|
1695
|
-
_getLabelNamesForSelectorCompletions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(metric, otherLabels, dataProvider) {
|
|
1787
|
+
_getLabelNamesForSelectorCompletions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(metric, hasOperator, otherLabels, dataProvider) {
|
|
1696
1788
|
return _regenerator().w(function (_context4) {
|
|
1697
1789
|
while (1) switch (_context4.n) {
|
|
1698
1790
|
case 0:
|
|
1699
|
-
return _context4.a(2, getLabelNamesForCompletions(metric, '=', true, otherLabels, dataProvider));
|
|
1791
|
+
return _context4.a(2, getLabelNamesForCompletions(metric, hasOperator ? '' : '=', true, otherLabels, dataProvider));
|
|
1700
1792
|
}
|
|
1701
1793
|
}, _callee4);
|
|
1702
1794
|
}));
|
|
1703
1795
|
return _getLabelNamesForSelectorCompletions.apply(this, arguments);
|
|
1704
1796
|
}
|
|
1705
|
-
function getLabelNamesForByCompletions(
|
|
1797
|
+
function getLabelNamesForByCompletions(_x12, _x13, _x14) {
|
|
1706
1798
|
return _getLabelNamesForByCompletions.apply(this, arguments);
|
|
1707
1799
|
}
|
|
1708
1800
|
function _getLabelNamesForByCompletions() {
|
|
@@ -1716,7 +1808,7 @@ function _getLabelNamesForByCompletions() {
|
|
|
1716
1808
|
}));
|
|
1717
1809
|
return _getLabelNamesForByCompletions.apply(this, arguments);
|
|
1718
1810
|
}
|
|
1719
|
-
function getLabelValues(
|
|
1811
|
+
function getLabelValues(_x15, _x16, _x17, _x18) {
|
|
1720
1812
|
return _getLabelValues.apply(this, arguments);
|
|
1721
1813
|
}
|
|
1722
1814
|
function _getLabelValues() {
|
|
@@ -1781,7 +1873,7 @@ function _getLabelValues() {
|
|
|
1781
1873
|
}));
|
|
1782
1874
|
return _getLabelValues.apply(this, arguments);
|
|
1783
1875
|
}
|
|
1784
|
-
function getLabelValuesForMetricCompletions(
|
|
1876
|
+
function getLabelValuesForMetricCompletions(_x19, _x20, _x21, _x22, _x23) {
|
|
1785
1877
|
return _getLabelValuesForMetricCompletions.apply(this, arguments);
|
|
1786
1878
|
}
|
|
1787
1879
|
function _getLabelValuesForMetricCompletions() {
|
|
@@ -1826,7 +1918,7 @@ function getCompletions(situation, dataProvider) {
|
|
|
1826
1918
|
return Promise.resolve([].concat(historyCompletions, FUNCTION_COMPLETIONS, metricNames));
|
|
1827
1919
|
}
|
|
1828
1920
|
case 'IN_LABEL_SELECTOR_NO_LABEL_NAME':
|
|
1829
|
-
return getLabelNamesForSelectorCompletions(situation.metricName, situation.otherLabels, dataProvider);
|
|
1921
|
+
return getLabelNamesForSelectorCompletions(situation.metricName, situation.hasOperator, situation.otherLabels, dataProvider);
|
|
1830
1922
|
case 'IN_GROUPING':
|
|
1831
1923
|
return getLabelNamesForByCompletions(situation.metricName, situation.otherLabels, dataProvider);
|
|
1832
1924
|
case 'IN_LABEL_SELECTOR_WITH_LABEL_NAME':
|
|
@@ -2049,6 +2141,8 @@ function PromQLEditor(props) {
|
|
|
2049
2141
|
var containerRef = React.useRef(null);
|
|
2050
2142
|
var dataProviderRef = React.useRef(null);
|
|
2051
2143
|
var editorRef = React.useRef(null);
|
|
2144
|
+
var previousContentRef = React.useRef('');
|
|
2145
|
+
var lastDeletionTriggerTimeRef = React.useRef(0);
|
|
2052
2146
|
var styles = getStyles(placeholder);
|
|
2053
2147
|
var handleEditorDidMount = function handleEditorDidMount(editor) {
|
|
2054
2148
|
editorRef.current = editor;
|
|
@@ -2132,6 +2226,10 @@ function PromQLEditor(props) {
|
|
|
2132
2226
|
editor.addCommand(monaco.KeyCode.Enter, function () {
|
|
2133
2227
|
onEnter == null || onEnter(editor.getValue());
|
|
2134
2228
|
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
2229
|
+
// Initialize previous content tracking
|
|
2230
|
+
previousContentRef.current = editor.getValue();
|
|
2231
|
+
lastDeletionTriggerTimeRef.current = 0;
|
|
2232
|
+
var DELETION_TRIGGER_DEBOUNCE_MS = 1000;
|
|
2135
2233
|
editor.onDidChangeModelContent(function () {
|
|
2136
2234
|
var model = editor.getModel();
|
|
2137
2235
|
if (model) {
|
|
@@ -2146,6 +2244,20 @@ function PromQLEditor(props) {
|
|
|
2146
2244
|
}, boundary);
|
|
2147
2245
|
});
|
|
2148
2246
|
monaco.editor.setModelMarkers(model, 'owner', markers);
|
|
2247
|
+
// Detect deletion and trigger completion
|
|
2248
|
+
var previousContent = previousContentRef.current;
|
|
2249
|
+
var isDeletion = query.length < previousContent.length;
|
|
2250
|
+
if (isDeletion && enableAutocomplete) {
|
|
2251
|
+
var now = Date.now();
|
|
2252
|
+
if (now - lastDeletionTriggerTimeRef.current >= DELETION_TRIGGER_DEBOUNCE_MS) {
|
|
2253
|
+
lastDeletionTriggerTimeRef.current = now;
|
|
2254
|
+
// Trigger completion after deletion
|
|
2255
|
+
setTimeout(function () {
|
|
2256
|
+
editor.trigger('keyboard', 'editor.action.triggerSuggest', {});
|
|
2257
|
+
}, 0);
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
previousContentRef.current = query;
|
|
2149
2261
|
}
|
|
2150
2262
|
});
|
|
2151
2263
|
editorDidMount == null || editorDidMount(editor);
|