Tempo: Provide tag value completion items consistently (#43773)

This commit is contained in:
Connor Lindsey 2022-01-10 07:37:35 -07:00 committed by GitHub
parent 2b967c4c55
commit 3d6e9076c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,10 @@ export default class TempoLanguageProvider extends LanguageProvider {
if (!value) {
return emptyResult;
}
if (text === '=') {
const query = value.endText.getText();
const isValue = query[query.indexOf(text) - 1] === '=';
if (isValue || text === '=') {
return this.getTagValueCompletionItems(value);
}
return this.getTagsCompletionItems();
@ -58,19 +61,17 @@ export default class TempoLanguageProvider extends LanguageProvider {
};
async getTagValueCompletionItems(value: Value) {
const tagNames = value.endText.getText().split(' ');
let tagName = tagNames[0];
// Get last item if multiple tags
if (tagNames.length > 1) {
tagName = tagNames[tagNames.length - 1];
}
tagName = tagName.slice(0, -1);
const tags = value.endText.getText().split(' ');
let tagName = tags[tags.length - 1] ?? '';
tagName = tagName.split('=')[0];
const response = await this.request(`/api/search/tag/${tagName}/values`, []);
const suggestions: CompletionItemGroup[] = [];
if (response && response.tagValues) {
suggestions.push({
label: `TagValues`,
label: `Tag Values`,
items: response.tagValues.map((tagValue: string) => ({ label: tagValue })),
});
}