diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index 854d6cabe4d..5dbd07ef1c2 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -125,6 +125,23 @@ function link(scope, elem, attrs) { } }); + let extCompleter = { + getCompletions: getExtCompletions + }; + + function getExtCompletions(editor, session, pos, prefix, callback) { + scope.getMetrics(prefix).then(results => { + let wordList = results; + callback(null, wordList.map(word => { + return { + caption: word, + value: word, + meta: "metric" + }; + })); + }); + } + function setLangMode(lang) { let aceModeName = `ace/mode/${lang}`; fixModuleUrl("mode", lang); @@ -136,6 +153,7 @@ function link(scope, elem, attrs) { enableLiveAutocompletion: true, enableSnippets: true }); + codeEditor.completers.push(extCompleter); }); } @@ -157,7 +175,8 @@ export function codeEditorDirective() { template: editorTemplate, scope: { content: "=", - onChange: "&" + onChange: "&", + getMetrics: "=" }, link: link }; diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 206c2f012cf..146339e29fd 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -7,7 +7,9 @@