Tempo: Improve autocompletion for TraceQL editor (#74790)

This commit is contained in:
Fabrizio
2023-09-19 09:23:35 +02:00
committed by GitHub
parent 24350521be
commit 9113c6d959
6 changed files with 34 additions and 24 deletions

View File

@@ -4164,6 +4164,9 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"] [0, 0, 0, "Unexpected any. Specify a different type.", "1"]
], ],
"public/app/plugins/datasource/tempo/traceql/autocomplete.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/plugins/datasource/testdata/ConfigEditor.tsx:5381": [ "public/app/plugins/datasource/testdata/ConfigEditor.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"] [0, 0, 0, "Unexpected any. Specify a different type.", "0"]
], ],

View File

@@ -248,7 +248,7 @@
"@grafana/flamegraph": "workspace:*", "@grafana/flamegraph": "workspace:*",
"@grafana/google-sdk": "0.1.1", "@grafana/google-sdk": "0.1.1",
"@grafana/lezer-logql": "0.1.11", "@grafana/lezer-logql": "0.1.11",
"@grafana/lezer-traceql": "0.0.5", "@grafana/lezer-traceql": "0.0.6",
"@grafana/monaco-logql": "^0.0.7", "@grafana/monaco-logql": "^0.0.7",
"@grafana/runtime": "workspace:*", "@grafana/runtime": "workspace:*",
"@grafana/scenes": "^1.1.1", "@grafana/scenes": "^1.1.1",

View File

@@ -200,13 +200,18 @@ describe('CompletionProvider', () => {
])( ])(
'suggests operators that go after `|` (aggregators, selectorts, ...) - %s, %i', 'suggests operators that go after `|` (aggregators, selectorts, ...) - %s, %i',
async (input: string, offset: number) => { async (input: string, offset: number) => {
const { provider, model } = setup(input, offset); const { provider, model } = setup(input, offset, undefined, v2Tags);
const result = await provider.provideCompletionItems(model, emptyPosition); const result = await provider.provideCompletionItems(model, emptyPosition);
expect((result! as monacoTypes.languages.CompletionList).suggestions).toEqual( expect((result! as monacoTypes.languages.CompletionList).suggestions).toEqual([
CompletionProvider.functions.map((s) => ...CompletionProvider.functions.map((s) =>
expect.objectContaining({ label: s.label, insertText: s.insertText, documentation: s.documentation }) expect.objectContaining({ label: s.label, insertText: s.insertText, documentation: s.documentation })
) ),
); ...scopes.map((s) => expect.objectContaining({ label: s, insertText: s })),
...intrinsics.map((s) => expect.objectContaining({ label: s, insertText: s })),
expect.objectContaining({ label: 'cluster', insertText: '.cluster' }),
expect.objectContaining({ label: 'container', insertText: '.container' }),
expect.objectContaining({ label: 'db', insertText: '.db' }),
]);
} }
); );

View File

@@ -337,11 +337,15 @@ export class CompletionProvider implements monacoTypes.languages.CompletionItemP
type: 'OPERATOR', type: 'OPERATOR',
})); }));
case 'SPANSET_PIPELINE_AFTER_OPERATOR': case 'SPANSET_PIPELINE_AFTER_OPERATOR':
return CompletionProvider.functions.map((key) => ({ const functions = CompletionProvider.functions.map((key) => ({
...key, ...key,
insertTextRules: this.monaco?.languages.CompletionItemInsertTextRule?.InsertAsSnippet, insertTextRules: this.monaco?.languages.CompletionItemInsertTextRule?.InsertAsSnippet,
type: 'FUNCTION', type: 'FUNCTION' as CompletionType,
})); }));
const tags = this.getScopesCompletions()
.concat(this.getIntrinsicsCompletions())
.concat(this.getTagsCompletions('.'));
return [...functions, ...tags];
case 'SPANSET_COMPARISON_OPERATORS': case 'SPANSET_COMPARISON_OPERATORS':
return CompletionProvider.comparisonOps.map((key) => ({ return CompletionProvider.comparisonOps.map((key) => ({
...key, ...key,

View File

@@ -11,6 +11,7 @@ import {
IntrinsicField, IntrinsicField,
Or, Or,
parser, parser,
Pipe,
ScalarFilter, ScalarFilter,
SelectArgs, SelectArgs,
SpansetFilter, SpansetFilter,
@@ -205,10 +206,6 @@ const RESOLVERS: Resolver[] = [
type: 'SPANSET_EXPRESSION_OPERATORS_WITH_MISSING_CLOSED_BRACE', type: 'SPANSET_EXPRESSION_OPERATORS_WITH_MISSING_CLOSED_BRACE',
}), }),
}, },
{
path: [ERROR_NODE_ID, SpansetPipeline],
fun: resolveSpansetPipeline,
},
{ {
path: [ERROR_NODE_ID, Aggregate], path: [ERROR_NODE_ID, Aggregate],
fun: resolveAttributeForFunction, fun: resolveAttributeForFunction,
@@ -219,11 +216,7 @@ const RESOLVERS: Resolver[] = [
}, },
{ {
path: [ERROR_NODE_ID, SpansetPipelineExpression], path: [ERROR_NODE_ID, SpansetPipelineExpression],
fun: () => { fun: resolveSpansetPipeline,
return {
type: 'NEW_SPANSET',
};
},
}, },
{ {
path: [ERROR_NODE_ID, ScalarFilter, SpansetPipeline], path: [ERROR_NODE_ID, ScalarFilter, SpansetPipeline],
@@ -386,8 +379,13 @@ function resolveAttributeForFunction(node: SyntaxNode, _0: string, _1: number):
}; };
} }
function resolveSpansetPipeline(_0: SyntaxNode, _1: string, _2: number): SituationType { function resolveSpansetPipeline(node: SyntaxNode, _1: string, _2: number): SituationType {
if (node.prevSibling?.type.id === Pipe) {
return {
type: 'SPANSET_PIPELINE_AFTER_OPERATOR',
};
}
return { return {
type: 'SPANSET_PIPELINE_AFTER_OPERATOR', type: 'NEW_SPANSET',
}; };
} }

View File

@@ -3948,12 +3948,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@grafana/lezer-traceql@npm:0.0.5": "@grafana/lezer-traceql@npm:0.0.6":
version: 0.0.5 version: 0.0.6
resolution: "@grafana/lezer-traceql@npm:0.0.5" resolution: "@grafana/lezer-traceql@npm:0.0.6"
peerDependencies: peerDependencies:
"@lezer/lr": ^1.3.0 "@lezer/lr": ^1.3.0
checksum: 6fcf48acde1e444c155a4b4009f4c7211843b07960713821a2649b1db0e0ef819fd1062eec101173c2e6b8249b253faf0b6052e96f551663618fd2fe0d17e3c9 checksum: 166a30c38f4f78e1768e80f724176b71becf3fa51414bc8bea4c2c5288a92d1f8b7872280a06c0d3f7f7608b174e5fc930e1af39339b2c2fdf627fb7ac14c6b4
languageName: node languageName: node
linkType: hard linkType: hard
@@ -19699,7 +19699,7 @@ __metadata:
"@grafana/flamegraph": "workspace:*" "@grafana/flamegraph": "workspace:*"
"@grafana/google-sdk": 0.1.1 "@grafana/google-sdk": 0.1.1
"@grafana/lezer-logql": 0.1.11 "@grafana/lezer-logql": 0.1.11
"@grafana/lezer-traceql": 0.0.5 "@grafana/lezer-traceql": 0.0.6
"@grafana/monaco-logql": ^0.0.7 "@grafana/monaco-logql": ^0.0.7
"@grafana/runtime": "workspace:*" "@grafana/runtime": "workspace:*"
"@grafana/scenes": ^1.1.1 "@grafana/scenes": ^1.1.1