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

* prometheus: monaco: stricter autocomplete

* autocomplete on space
pull/41077/head
Gábor Farkas 4 years ago committed by GitHub
parent e8a30f651e
commit fcaf9e68ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      public/app/plugins/datasource/prometheus/components/monaco-query-field/monaco-completion-provider/index.ts
  2. 2
      public/app/plugins/datasource/prometheus/components/monaco-query-field/monaco-completion-provider/intent.test.ts
  3. 13
      public/app/plugins/datasource/prometheus/components/monaco-query-field/monaco-completion-provider/intent.ts

@ -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'],

Loading…
Cancel
Save