Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 () => {
const { provider, model } = setup('{ foo }', 6, defaultTags);
const result = await provider.provideCompletionItems(
Expand All @@ -114,10 +125,9 @@ describe('CompletionProvider', () => {
model as unknown as monacoTypes.editor.ITextModel,
{} as monacoTypes.Position
);
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 })),
]);
expect((result! as monacoTypes.languages.CompletionList).suggestions).toEqual(
defaultTags.map((s) => expect.objectContaining({ label: s, insertText: s }))
);
});

it('suggests logical operators and close bracket after the value', async () => {
Expand Down
14 changes: 13 additions & 1 deletion public/app/plugins/datasource/tempo/traceql/autocomplete.ts
Expand Up @@ -120,10 +120,13 @@ export class CompletionProvider implements monacoTypes.languages.CompletionItemP
}
case 'SPANSET_EMPTY':
return this.getScopesCompletions().concat(this.getIntrinsicsCompletions()).concat(this.getTagsCompletions('.'));
case 'SPANSET_ONLY_DOT': {
return this.getTagsCompletions();
}
case 'SPANSET_IN_NAME':
return this.getScopesCompletions().concat(this.getIntrinsicsCompletions()).concat(this.getTagsCompletions());
case 'SPANSET_IN_NAME_SCOPE':
return this.getIntrinsicsCompletions().concat(this.getTagsCompletions());
return this.getTagsCompletions();
case 'SPANSET_AFTER_NAME':
return CompletionProvider.operators.map((key) => ({
label: key,
Expand Down Expand Up @@ -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>\.)?$/);

// We already have a (potentially partial) tag name so let's check if there's an operator declared
Expand Down Expand Up @@ -344,6 +353,9 @@ export type Situation =
| {
type: 'SPANSET_EMPTY';
}
| {
type: 'SPANSET_ONLY_DOT';
}
| {
type: 'SPANSET_AFTER_NAME';
}
Expand Down