@fc-components/monaco-editor 0.1.24 → 0.1.26
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 +137 -11
- 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 +138 -12
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/situation.d.ts +1 -0
- package/dist/promql/index.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 +42 -0
|
@@ -3,7 +3,7 @@ import MonacoEditor from 'react-monaco-editor';
|
|
|
3
3
|
import * as monaco from 'monaco-editor';
|
|
4
4
|
import { languages, Range, editor, Selection, KeyMod, KeyCode, MarkerSeverity } from 'monaco-editor';
|
|
5
5
|
import { promLanguageDefinition } from 'monaco-promql';
|
|
6
|
-
import { parser, LabelMatchers, VectorSelector, PromQL, FunctionCallBody, StringLiteral,
|
|
6
|
+
import { parser, LabelName, UnquotedLabelMatcher, LabelMatchers, VectorSelector, PromQL, Identifier, FunctionCallBody, StringLiteral, BinaryExpr, NumberDurationLiteralInDurationContext, MatrixSelector, GroupingLabels, AggregateModifier, AggregateExpr, MatchOp, EqlSingle, EqlRegex, Neq, NeqRegex } from '@fc-components/lezer-metricsql';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import { css } from '@emotion/css';
|
|
9
9
|
|
|
@@ -1248,11 +1248,29 @@ function isPathMatch(resolverPath, cursorPath) {
|
|
|
1248
1248
|
}
|
|
1249
1249
|
var ERROR_NODE_NAME = 0; // this is used as error-id
|
|
1250
1250
|
var RESOLVERS = [{
|
|
1251
|
+
path: [LabelName, UnquotedLabelMatcher],
|
|
1252
|
+
fun: resolveLabelName
|
|
1253
|
+
}, {
|
|
1254
|
+
path: [UnquotedLabelMatcher, LabelMatchers],
|
|
1255
|
+
fun: resolveLabelName
|
|
1256
|
+
}, {
|
|
1251
1257
|
path: [LabelMatchers, VectorSelector],
|
|
1252
1258
|
fun: resolveLabelKeysWithEquals
|
|
1259
|
+
}, {
|
|
1260
|
+
path: [LabelMatchers, VectorSelector, PromQL],
|
|
1261
|
+
fun: resolveLabelKeysWithEquals
|
|
1253
1262
|
}, {
|
|
1254
1263
|
path: [PromQL],
|
|
1255
1264
|
fun: resolveTopLevel
|
|
1265
|
+
}, {
|
|
1266
|
+
path: [VectorSelector, PromQL],
|
|
1267
|
+
fun: resolveTopLevel
|
|
1268
|
+
}, {
|
|
1269
|
+
path: [Identifier, VectorSelector],
|
|
1270
|
+
fun: resolveTopLevel
|
|
1271
|
+
}, {
|
|
1272
|
+
path: [Identifier, VectorSelector, PromQL],
|
|
1273
|
+
fun: resolveTopLevel
|
|
1256
1274
|
}, {
|
|
1257
1275
|
path: [FunctionCallBody],
|
|
1258
1276
|
fun: resolveInFunction
|
|
@@ -1264,7 +1282,7 @@ var RESOLVERS = [{
|
|
|
1264
1282
|
fun: resolveTopLevel
|
|
1265
1283
|
}, {
|
|
1266
1284
|
path: [ERROR_NODE_NAME, UnquotedLabelMatcher],
|
|
1267
|
-
fun:
|
|
1285
|
+
fun: resolveErrorInLabelMatcher
|
|
1268
1286
|
}, {
|
|
1269
1287
|
path: [ERROR_NODE_NAME, NumberDurationLiteralInDurationContext, MatrixSelector],
|
|
1270
1288
|
fun: resolveDurations
|
|
@@ -1406,6 +1424,27 @@ function resolveLabelMatcher(node, text, _pos) {
|
|
|
1406
1424
|
otherLabels: otherLabels
|
|
1407
1425
|
};
|
|
1408
1426
|
}
|
|
1427
|
+
function resolveErrorInLabelMatcher(node, text, pos) {
|
|
1428
|
+
// 处理错误节点在 UnquotedLabelMatcher 中的情况
|
|
1429
|
+
// 需要判断是删除值还是删除名称
|
|
1430
|
+
var parent = walk(node, [['parent', UnquotedLabelMatcher]]);
|
|
1431
|
+
if (parent === null) {
|
|
1432
|
+
return null;
|
|
1433
|
+
}
|
|
1434
|
+
var labelNameNode = walk(parent, [['firstChild', LabelName]]);
|
|
1435
|
+
// 情况1: 有完整的标签名 -> 提示 label value
|
|
1436
|
+
if (labelNameNode !== null) {
|
|
1437
|
+
// 检查是否有 MatchOp(=, =~, !=, !~)
|
|
1438
|
+
var hasMatchOp = walk(labelNameNode, [['nextSibling', MatchOp]]) !== null;
|
|
1439
|
+
if (hasMatchOp) {
|
|
1440
|
+
// 这是值场景,使用 resolveLabelMatcher 的逻辑
|
|
1441
|
+
return resolveLabelMatcher(node, text);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
// 情况2: 没有完整的标签名或没有 MatchOp -> 提示 label name
|
|
1445
|
+
// 使用 resolveLabelName 的逻辑
|
|
1446
|
+
return resolveLabelName(parent, text, pos);
|
|
1447
|
+
}
|
|
1409
1448
|
function resolveTopLevel() {
|
|
1410
1449
|
return {
|
|
1411
1450
|
type: 'AT_ROOT'
|
|
@@ -1421,6 +1460,55 @@ function resolveDurations() {
|
|
|
1421
1460
|
type: 'IN_DURATION'
|
|
1422
1461
|
};
|
|
1423
1462
|
}
|
|
1463
|
+
function resolveLabelName(node, text, pos) {
|
|
1464
|
+
var labelMatcherNode = node;
|
|
1465
|
+
// 如果节点是错误节点,尝试找到其父节点 UnquotedLabelMatcher
|
|
1466
|
+
if (node.type.isError) {
|
|
1467
|
+
var parent = node.parent;
|
|
1468
|
+
if (parent !== null && parent.type.id === UnquotedLabelMatcher) {
|
|
1469
|
+
labelMatcherNode = parent;
|
|
1470
|
+
} else {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
} else if (node.type.id === LabelName) {
|
|
1474
|
+
labelMatcherNode = walk(node, [['parent', UnquotedLabelMatcher]]);
|
|
1475
|
+
}
|
|
1476
|
+
if (labelMatcherNode === null || labelMatcherNode.type.id !== UnquotedLabelMatcher) {
|
|
1477
|
+
return null;
|
|
1478
|
+
}
|
|
1479
|
+
var labelNameNode = walk(labelMatcherNode, [['firstChild', LabelName]]);
|
|
1480
|
+
if (labelNameNode === null) {
|
|
1481
|
+
return null;
|
|
1482
|
+
}
|
|
1483
|
+
if (pos > labelNameNode.to) {
|
|
1484
|
+
return null;
|
|
1485
|
+
}
|
|
1486
|
+
var labelMatchersNode = walk(labelMatcherNode, [['parent', LabelMatchers]]);
|
|
1487
|
+
if (labelMatchersNode === null) {
|
|
1488
|
+
return null;
|
|
1489
|
+
}
|
|
1490
|
+
var currentLabelName = getNodeText(labelNameNode, text);
|
|
1491
|
+
var allLabels = getLabels(labelMatchersNode, text);
|
|
1492
|
+
var otherLabels = allLabels.filter(function (label) {
|
|
1493
|
+
return label.name !== currentLabelName;
|
|
1494
|
+
});
|
|
1495
|
+
var hasOperator = walk(labelNameNode, [['nextSibling', MatchOp]]) !== null;
|
|
1496
|
+
var metricNameNode = walk(labelMatchersNode, [['parent', VectorSelector], ['firstChild', Identifier]]);
|
|
1497
|
+
if (metricNameNode === null) {
|
|
1498
|
+
return {
|
|
1499
|
+
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1500
|
+
otherLabels: otherLabels,
|
|
1501
|
+
hasOperator: hasOperator
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
var metricName = getNodeText(metricNameNode, text);
|
|
1505
|
+
return {
|
|
1506
|
+
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1507
|
+
metricName: metricName,
|
|
1508
|
+
otherLabels: otherLabels,
|
|
1509
|
+
hasOperator: hasOperator
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1424
1512
|
function resolveLabelKeysWithEquals(node, text, pos) {
|
|
1425
1513
|
// next false positive:
|
|
1426
1514
|
// `something{a="1"^}`
|
|
@@ -1443,14 +1531,16 @@ function resolveLabelKeysWithEquals(node, text, pos) {
|
|
|
1443
1531
|
// we are probably in a situation without a metric name.
|
|
1444
1532
|
return {
|
|
1445
1533
|
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1446
|
-
otherLabels: otherLabels
|
|
1534
|
+
otherLabels: otherLabels,
|
|
1535
|
+
hasOperator: false
|
|
1447
1536
|
};
|
|
1448
1537
|
}
|
|
1449
1538
|
var metricName = getNodeText(metricNameNode, text);
|
|
1450
1539
|
return {
|
|
1451
1540
|
type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',
|
|
1452
1541
|
metricName: metricName,
|
|
1453
|
-
otherLabels: otherLabels
|
|
1542
|
+
otherLabels: otherLabels,
|
|
1543
|
+
hasOperator: false
|
|
1454
1544
|
};
|
|
1455
1545
|
}
|
|
1456
1546
|
// we find the first error-node in the tree that is at the cursor-position.
|
|
@@ -1498,8 +1588,10 @@ function getSituation(text, pos) {
|
|
|
1498
1588
|
var cur = maybeErrorNode != null ? maybeErrorNode.cursor() : tree.cursorAt(pos);
|
|
1499
1589
|
var currentNode = cur.node;
|
|
1500
1590
|
var ids = [cur.type.id];
|
|
1591
|
+
// const names = [cur.type.name];
|
|
1501
1592
|
while (cur.parent()) {
|
|
1502
1593
|
ids.push(cur.type.id);
|
|
1594
|
+
// names.push(cur.type.name);
|
|
1503
1595
|
}
|
|
1504
1596
|
for (var _iterator3 = _createForOfIteratorHelperLoose(RESOLVERS), _step3; !(_step3 = _iterator3()).done;) {
|
|
1505
1597
|
var resolver = _step3.value;
|
|
@@ -1682,21 +1774,21 @@ function _getLabelNamesForCompletions() {
|
|
|
1682
1774
|
}));
|
|
1683
1775
|
return _getLabelNamesForCompletions.apply(this, arguments);
|
|
1684
1776
|
}
|
|
1685
|
-
function getLabelNamesForSelectorCompletions(_x0, _x1, _x10) {
|
|
1777
|
+
function getLabelNamesForSelectorCompletions(_x0, _x1, _x10, _x11) {
|
|
1686
1778
|
return _getLabelNamesForSelectorCompletions.apply(this, arguments);
|
|
1687
1779
|
}
|
|
1688
1780
|
function _getLabelNamesForSelectorCompletions() {
|
|
1689
|
-
_getLabelNamesForSelectorCompletions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(metric, otherLabels, dataProvider) {
|
|
1781
|
+
_getLabelNamesForSelectorCompletions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(metric, hasOperator, otherLabels, dataProvider) {
|
|
1690
1782
|
return _regenerator().w(function (_context4) {
|
|
1691
1783
|
while (1) switch (_context4.n) {
|
|
1692
1784
|
case 0:
|
|
1693
|
-
return _context4.a(2, getLabelNamesForCompletions(metric, '=', true, otherLabels, dataProvider));
|
|
1785
|
+
return _context4.a(2, getLabelNamesForCompletions(metric, hasOperator ? '' : '=', true, otherLabels, dataProvider));
|
|
1694
1786
|
}
|
|
1695
1787
|
}, _callee4);
|
|
1696
1788
|
}));
|
|
1697
1789
|
return _getLabelNamesForSelectorCompletions.apply(this, arguments);
|
|
1698
1790
|
}
|
|
1699
|
-
function getLabelNamesForByCompletions(
|
|
1791
|
+
function getLabelNamesForByCompletions(_x12, _x13, _x14) {
|
|
1700
1792
|
return _getLabelNamesForByCompletions.apply(this, arguments);
|
|
1701
1793
|
}
|
|
1702
1794
|
function _getLabelNamesForByCompletions() {
|
|
@@ -1710,7 +1802,7 @@ function _getLabelNamesForByCompletions() {
|
|
|
1710
1802
|
}));
|
|
1711
1803
|
return _getLabelNamesForByCompletions.apply(this, arguments);
|
|
1712
1804
|
}
|
|
1713
|
-
function getLabelValues(
|
|
1805
|
+
function getLabelValues(_x15, _x16, _x17, _x18) {
|
|
1714
1806
|
return _getLabelValues.apply(this, arguments);
|
|
1715
1807
|
}
|
|
1716
1808
|
function _getLabelValues() {
|
|
@@ -1775,7 +1867,7 @@ function _getLabelValues() {
|
|
|
1775
1867
|
}));
|
|
1776
1868
|
return _getLabelValues.apply(this, arguments);
|
|
1777
1869
|
}
|
|
1778
|
-
function getLabelValuesForMetricCompletions(
|
|
1870
|
+
function getLabelValuesForMetricCompletions(_x19, _x20, _x21, _x22, _x23) {
|
|
1779
1871
|
return _getLabelValuesForMetricCompletions.apply(this, arguments);
|
|
1780
1872
|
}
|
|
1781
1873
|
function _getLabelValuesForMetricCompletions() {
|
|
@@ -1820,7 +1912,7 @@ function getCompletions(situation, dataProvider) {
|
|
|
1820
1912
|
return Promise.resolve([].concat(historyCompletions, FUNCTION_COMPLETIONS, metricNames));
|
|
1821
1913
|
}
|
|
1822
1914
|
case 'IN_LABEL_SELECTOR_NO_LABEL_NAME':
|
|
1823
|
-
return getLabelNamesForSelectorCompletions(situation.metricName, situation.otherLabels, dataProvider);
|
|
1915
|
+
return getLabelNamesForSelectorCompletions(situation.metricName, situation.hasOperator, situation.otherLabels, dataProvider);
|
|
1824
1916
|
case 'IN_GROUPING':
|
|
1825
1917
|
return getLabelNamesForByCompletions(situation.metricName, situation.otherLabels, dataProvider);
|
|
1826
1918
|
case 'IN_LABEL_SELECTOR_WITH_LABEL_NAME':
|
|
@@ -2038,11 +2130,15 @@ function PromQLEditor(props) {
|
|
|
2038
2130
|
onChange = props.onChange,
|
|
2039
2131
|
onEnter = props.onEnter,
|
|
2040
2132
|
onBlur = props.onBlur,
|
|
2041
|
-
editorDidMount = props.editorDidMount
|
|
2133
|
+
editorDidMount = props.editorDidMount,
|
|
2134
|
+
_props$debugEscKey = props.debugEscKey,
|
|
2135
|
+
debugEscKey = _props$debugEscKey === void 0 ? false : _props$debugEscKey;
|
|
2042
2136
|
var autocompleteDisposeFun = useRef(null);
|
|
2043
2137
|
var containerRef = useRef(null);
|
|
2044
2138
|
var dataProviderRef = useRef(null);
|
|
2045
2139
|
var editorRef = useRef(null);
|
|
2140
|
+
var previousContentRef = useRef('');
|
|
2141
|
+
var lastDeletionTriggerTimeRef = useRef(0);
|
|
2046
2142
|
var styles = getStyles(placeholder);
|
|
2047
2143
|
var handleEditorDidMount = function handleEditorDidMount(editor$1) {
|
|
2048
2144
|
editorRef.current = editor$1;
|
|
@@ -2126,6 +2222,22 @@ function PromQLEditor(props) {
|
|
|
2126
2222
|
editor$1.addCommand(KeyCode.Enter, function () {
|
|
2127
2223
|
onEnter == null || onEnter(editor$1.getValue());
|
|
2128
2224
|
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
2225
|
+
editor$1.addCommand(KeyCode.Escape, function () {
|
|
2226
|
+
if (debugEscKey) {
|
|
2227
|
+
var _editor$_contextKeySe;
|
|
2228
|
+
var suggestWidgetVisible = editor$1 == null || (_editor$_contextKeySe = editor$1._contextKeyService) == null || _editor$_contextKeySe.getContextKeyValue == null ? void 0 : _editor$_contextKeySe.getContextKeyValue('suggestWidgetVisible');
|
|
2229
|
+
// eslint-disable-next-line no-console
|
|
2230
|
+
console.log('[PromQLEditor][ESC]', {
|
|
2231
|
+
suggestWidgetVisible: suggestWidgetVisible,
|
|
2232
|
+
valueLength: editor$1.getValue().length
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
editor$1.trigger('keyboard', 'hideSuggestWidget', {});
|
|
2236
|
+
}, 'suggestWidgetVisible && isEditorFocused' + id);
|
|
2237
|
+
// Initialize previous content tracking
|
|
2238
|
+
previousContentRef.current = editor$1.getValue();
|
|
2239
|
+
lastDeletionTriggerTimeRef.current = 0;
|
|
2240
|
+
var DELETION_TRIGGER_DEBOUNCE_MS = 1000;
|
|
2129
2241
|
editor$1.onDidChangeModelContent(function () {
|
|
2130
2242
|
var model = editor$1.getModel();
|
|
2131
2243
|
if (model) {
|
|
@@ -2140,6 +2252,20 @@ function PromQLEditor(props) {
|
|
|
2140
2252
|
}, boundary);
|
|
2141
2253
|
});
|
|
2142
2254
|
editor.setModelMarkers(model, 'owner', markers);
|
|
2255
|
+
// Detect deletion and trigger completion
|
|
2256
|
+
var previousContent = previousContentRef.current;
|
|
2257
|
+
var isDeletion = query.length < previousContent.length;
|
|
2258
|
+
if (isDeletion && enableAutocomplete) {
|
|
2259
|
+
var now = Date.now();
|
|
2260
|
+
if (now - lastDeletionTriggerTimeRef.current >= DELETION_TRIGGER_DEBOUNCE_MS) {
|
|
2261
|
+
lastDeletionTriggerTimeRef.current = now;
|
|
2262
|
+
// Trigger completion after deletion
|
|
2263
|
+
setTimeout(function () {
|
|
2264
|
+
editor$1.trigger('keyboard', 'editor.action.triggerSuggest', {});
|
|
2265
|
+
}, 0);
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
previousContentRef.current = query;
|
|
2143
2269
|
}
|
|
2144
2270
|
});
|
|
2145
2271
|
editorDidMount == null || editorDidMount(editor$1);
|