mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ace: prometheus completion improvements
This commit is contained in:
@@ -128,22 +128,6 @@ function link(scope, elem, attrs) {
|
||||
}
|
||||
});
|
||||
|
||||
let extCompleter = {
|
||||
identifierRegexps: [/[\[\]a-zA-Z_0-9=]/],
|
||||
getCompletions: function (editor, session, pos, prefix, callback) {
|
||||
console.log(pos);
|
||||
scope.getCompletions({$query: prefix}).then(results => {
|
||||
callback(null, results.map(hit => {
|
||||
return {
|
||||
caption: hit.word,
|
||||
value: hit.word,
|
||||
meta: hit.type
|
||||
};
|
||||
}));
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
function setLangMode(lang) {
|
||||
let aceModeName = `ace/mode/${lang}`;
|
||||
setModuleUrl("mode", lang);
|
||||
@@ -161,6 +145,8 @@ function link(scope, elem, attrs) {
|
||||
codeEditor.completers.push(scope.getCompleter());
|
||||
}
|
||||
});
|
||||
|
||||
codeEditor.setBehavioursEnabled(true);
|
||||
}
|
||||
|
||||
function setThemeMode(theme) {
|
||||
|
||||
@@ -9,12 +9,30 @@ export class PromCompleter {
|
||||
}
|
||||
|
||||
getCompletions(editor, session, pos, prefix, callback) {
|
||||
if (prefix === '[') {
|
||||
var vectors = [];
|
||||
for (let unit of ['s', 'm', 'h']) {
|
||||
for (let value of [1,5,10,30]) {
|
||||
vectors.push({caption: value+unit, value: '['+value+unit, meta: 'range vector'});
|
||||
}
|
||||
}
|
||||
callback(null, vectors);
|
||||
return;
|
||||
}
|
||||
|
||||
var query = prefix;
|
||||
var line = editor.session.getLine(pos.row);
|
||||
|
||||
return this.datasource.performSuggestQuery(query).then(metricNames => {
|
||||
callback(null, metricNames.map(name => {
|
||||
let value = name;
|
||||
if (prefix === '(') {
|
||||
value = '(' + name;
|
||||
}
|
||||
|
||||
return {
|
||||
caption: name,
|
||||
value: name,
|
||||
value: value,
|
||||
meta: 'metric',
|
||||
};
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user