prometheus: monaco: stricter autocomplete and handle space (#41028)

* prometheus: monaco: stricter autocomplete

* autocomplete on space
This commit is contained in:
Gábor Farkas
2021-10-29 08:22:40 +02:00
committed by GitHub
parent e8a30f651e
commit fcaf9e68ee
3 changed files with 16 additions and 1 deletions
@@ -74,7 +74,7 @@ export function getCompletionProvider(
};
return {
triggerCharacters: ['{', ',', '[', '(', '=', '~'],
triggerCharacters: ['{', ',', '[', '(', '=', '~', ' '],
provideCompletionItems,
};
}
@@ -46,6 +46,8 @@ describe('intent', () => {
assertIntent('something{}[^]', {
type: 'ALL_DURATIONS',
});
assertIntent('something{label~^}', null);
});
it('handles label names', () => {
@@ -389,7 +389,20 @@ function resolveDurations(node: SyntaxNode, text: string, pos: number): Intent {
};
}
function subTreeHasError(node: SyntaxNode): boolean {
return getNodeInSubtree(node, ERROR_NODE_NAME) !== null;
}
function resolveLabelKeysWithEquals(node: SyntaxNode, text: string, pos: number): Intent | null {
// for example `something{^}`
// there are some false positives that can end up in this situation, that we want
// to eliminate, for example: `something{a~^}`
// basically, if this subtree contains any error-node, we stop
if (subTreeHasError(node)) {
return null;
}
const metricNameNode = walk(node, [
['parent', 'VectorSelector'],
['firstChild', 'MetricIdentifier'],