From 2d29997bdae241186e05e2a44846375de7547b28 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Mon, 11 May 2020 16:10:49 +0200 Subject: [PATCH] CloudWatch/Logs: Fix suggestions of fields after comma (#24520) --- .../plugins/datasource/cloudwatch/language_provider.test.ts | 4 ++++ public/app/plugins/datasource/cloudwatch/language_provider.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/cloudwatch/language_provider.test.ts b/public/app/plugins/datasource/cloudwatch/language_provider.test.ts index f711498774a..5168b8990b8 100644 --- a/public/app/plugins/datasource/cloudwatch/language_provider.test.ts +++ b/public/app/plugins/datasource/cloudwatch/language_provider.test.ts @@ -40,6 +40,10 @@ describe('CloudWatchLanguageProvider', () => { await runSuggestionTest('fields field1, \\', [fields, FUNCTIONS.map(v => v.label)]); }); + it('should suggest fields and functions after comma with prefix', async () => { + await runSuggestionTest('fields field1, @mess\\', [fields, FUNCTIONS.map(v => v.label)]); + }); + it('should suggest fields and functions after display command', async () => { await runSuggestionTest('display \\', [fields, FUNCTIONS.map(v => v.label)]); }); diff --git a/public/app/plugins/datasource/cloudwatch/language_provider.ts b/public/app/plugins/datasource/cloudwatch/language_provider.ts index 125bbdbee81..7683d46efb6 100644 --- a/public/app/plugins/datasource/cloudwatch/language_provider.ts +++ b/public/app/plugins/datasource/cloudwatch/language_provider.ts @@ -165,7 +165,7 @@ export class CloudWatchLanguageProvider extends LanguageProvider { const currentTokenIsComma = curToken.content === ',' && curToken.types.includes('punctuation'); const currentTokenIsCommaOrAfterComma = - currentTokenIsComma || (curToken.prev?.content === ',' && curToken.prev.types.includes('punctuation')); + currentTokenIsComma || (prevToken?.content === ',' && prevToken?.types.includes('punctuation')); // We only show suggestions if we are after a command or after a comma which is a field separator if (!(currentTokenIsAfterCommand || currentTokenIsCommaOrAfterComma)) {