don't remove last ] if token type is string

This commit is contained in:
Mitsuhiro Tanda 2018-03-15 17:37:49 +09:00
parent 10012f8ffe
commit bce5b2d56e

View File

@ -5,7 +5,6 @@ export class PromCompleter {
labelQueryCache: any;
labelNameCache: any;
labelValueCache: any;
templateVariableCompletions: any;
identifierRegexps = [/\[/, /[a-zA-Z0-9_:]/];
@ -13,34 +12,34 @@ export class PromCompleter {
this.labelQueryCache = {};
this.labelNameCache = {};
this.labelValueCache = {};
this.templateVariableCompletions = _.flatten(
this.templateSrv.variables.map(variable => {
return [
{
caption: '$' + variable.name,
value: '$' + variable.name,
meta: 'variable.other',
score: Number.MAX_VALUE,
},
{
caption: '[[' + variable.name + ']',
value: '[[' + variable.name + ']',
meta: 'variable.other',
score: Number.MAX_VALUE,
},
];
})
);
}
getCompletions(editor, session, pos, prefix, callback) {
let token = session.getTokenAt(pos.row, pos.column);
let wrappedCallback = (err, completions) => {
completions = completions.concat(this.templateVariableCompletions);
let templateVariableCompletions = _.flatten(
this.templateSrv.variables.map(variable => {
let suffix = token.type.indexOf('string') === 0 ? ']]' : ']';
return [
{
caption: '$' + variable.name,
value: '$' + variable.name,
meta: 'variable.other',
score: Number.MAX_VALUE,
},
{
caption: '[[' + variable.name + suffix,
value: '[[' + variable.name + suffix,
meta: 'variable.other',
score: Number.MAX_VALUE,
},
];
})
);
completions = completions.concat(templateVariableCompletions);
return callback(err, completions);
};
let token = session.getTokenAt(pos.row, pos.column);
switch (token.type) {
case 'entity.name.tag.label-matcher':
this.getCompletionsForLabelMatcherName(session, pos).then(completions => {