Tempo: Fix TraceQL autocomplete issues (#60058) (#60125)

This commit is contained in:
Hamas Shafiq
2022-12-12 14:49:18 +00:00
committed by GitHub
parent 61cd9eeb24
commit 583aafbbd8
2 changed files with 27 additions and 5 deletions
@@ -97,6 +97,17 @@ describe('CompletionProvider', () => {
]); ]);
}); });
it('only suggests tags after typing the global attribute scope', async () => {
const { provider, model } = setup('{.}', 2, defaultTags);
const result = await provider.provideCompletionItems(
model as unknown as monacoTypes.editor.ITextModel,
{} as monacoTypes.Position
);
expect((result! as monacoTypes.languages.CompletionList).suggestions).toEqual(
defaultTags.map((s) => expect.objectContaining({ label: s, insertText: s }))
);
});
it('suggests operators after a space after the tag name', async () => { it('suggests operators after a space after the tag name', async () => {
const { provider, model } = setup('{ foo }', 6, defaultTags); const { provider, model } = setup('{ foo }', 6, defaultTags);
const result = await provider.provideCompletionItems( const result = await provider.provideCompletionItems(
@@ -114,10 +125,9 @@ describe('CompletionProvider', () => {
model as unknown as monacoTypes.editor.ITextModel, model as unknown as monacoTypes.editor.ITextModel,
{} as monacoTypes.Position {} as monacoTypes.Position
); );
expect((result! as monacoTypes.languages.CompletionList).suggestions).toEqual([ expect((result! as monacoTypes.languages.CompletionList).suggestions).toEqual(
...CompletionProvider.intrinsics.map((s) => expect.objectContaining({ label: s, insertText: s })), defaultTags.map((s) => expect.objectContaining({ label: s, insertText: s }))
...defaultTags.map((s) => expect.objectContaining({ label: s, insertText: s })), );
]);
}); });
it('suggests logical operators and close bracket after the value', async () => { it('suggests logical operators and close bracket after the value', async () => {
@@ -120,10 +120,13 @@ export class CompletionProvider implements monacoTypes.languages.CompletionItemP
} }
case 'SPANSET_EMPTY': case 'SPANSET_EMPTY':
return this.getScopesCompletions().concat(this.getIntrinsicsCompletions()).concat(this.getTagsCompletions('.')); return this.getScopesCompletions().concat(this.getIntrinsicsCompletions()).concat(this.getTagsCompletions('.'));
case 'SPANSET_ONLY_DOT': {
return this.getTagsCompletions();
}
case 'SPANSET_IN_NAME': case 'SPANSET_IN_NAME':
return this.getScopesCompletions().concat(this.getIntrinsicsCompletions()).concat(this.getTagsCompletions()); return this.getScopesCompletions().concat(this.getIntrinsicsCompletions()).concat(this.getTagsCompletions());
case 'SPANSET_IN_NAME_SCOPE': case 'SPANSET_IN_NAME_SCOPE':
return this.getIntrinsicsCompletions().concat(this.getTagsCompletions()); return this.getTagsCompletions();
case 'SPANSET_AFTER_NAME': case 'SPANSET_AFTER_NAME':
return CompletionProvider.operators.map((key) => ({ return CompletionProvider.operators.map((key) => ({
label: key, label: key,
@@ -223,6 +226,12 @@ export class CompletionProvider implements monacoTypes.languages.CompletionItemP
}; };
} }
if (nameFull === '.') {
return {
type: 'SPANSET_ONLY_DOT',
};
}
const nameMatched = nameFull.match(/^(?<pre_dot>\.)?(?<word>\w[\w./-]*\w)(?<post_dot>\.)?$/); const nameMatched = nameFull.match(/^(?<pre_dot>\.)?(?<word>\w[\w./-]*\w)(?<post_dot>\.)?$/);
// We already have a (potentially partial) tag name so let's check if there's an operator declared // We already have a (potentially partial) tag name so let's check if there's an operator declared
@@ -344,6 +353,9 @@ export type Situation =
| { | {
type: 'SPANSET_EMPTY'; type: 'SPANSET_EMPTY';
} }
| {
type: 'SPANSET_ONLY_DOT';
}
| { | {
type: 'SPANSET_AFTER_NAME'; type: 'SPANSET_AFTER_NAME';
} }