From 2c8d6667ec45f747db25f456a524e50242ff454b Mon Sep 17 00:00:00 2001 From: Tai Lai Date: Fri, 30 Aug 2024 15:45:25 -0700 Subject: [PATCH] fix(amazonq): update security scan languages (#5523) ## Problem Sometimes security issues have a Diagnostic but not SecurityIssueHover issue. This happens when the document's languageId is not enabled when registering the hover/code actions provider. ## Solution Update the enabled languageIds for security scans feature. --- License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --- .../util/securityScanLanguageContext.test.ts | 12 ++++++++++++ packages/core/src/codewhisperer/activation.ts | 4 ++-- packages/core/src/codewhisperer/models/constants.ts | 6 ++++++ .../util/securityScanLanguageContext.ts | 6 ++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/amazonq/test/unit/codewhisperer/util/securityScanLanguageContext.test.ts b/packages/amazonq/test/unit/codewhisperer/util/securityScanLanguageContext.test.ts index 335e99e9e63..71ece8c66a9 100644 --- a/packages/amazonq/test/unit/codewhisperer/util/securityScanLanguageContext.test.ts +++ b/packages/amazonq/test/unit/codewhisperer/util/securityScanLanguageContext.test.ts @@ -39,6 +39,12 @@ describe('securityScanLanguageContext', function () { ['html', false], ['r', false], ['vb', false], + ['xml', false], + ['toml', false], + ['pip-requirements', false], + ['java-properties', false], + ['go.mod', false], + ['go.sum', false], ] beforeEach(async function () { @@ -100,6 +106,12 @@ describe('securityScanLanguageContext', function () { ['packer', 'tf'], ['plaintext', 'plaintext'], ['jsonc', 'json'], + ['xml', 'plaintext'], + ['toml', 'plaintext'], + ['pip-requirements', 'plaintext'], + ['java-properties', 'plaintext'], + ['go.mod', 'plaintext'], + ['go.sum', 'plaintext'], ] for (const [securityScanLanguageId, expectedCwsprLanguageId] of securityScanLanguageIds) { diff --git a/packages/core/src/codewhisperer/activation.ts b/packages/core/src/codewhisperer/activation.ts index d3ec18623a7..9d43ab9421a 100644 --- a/packages/core/src/codewhisperer/activation.ts +++ b/packages/core/src/codewhisperer/activation.ts @@ -283,11 +283,11 @@ export async function activate(context: ExtContext): Promise { ImportAdderProvider.instance ), vscode.languages.registerHoverProvider( - [...CodeWhispererConstants.platformLanguageIds], + [...CodeWhispererConstants.securityScanLanguageIds], SecurityIssueHoverProvider.instance ), vscode.languages.registerCodeActionsProvider( - [...CodeWhispererConstants.platformLanguageIds], + [...CodeWhispererConstants.securityScanLanguageIds], SecurityIssueCodeActionProvider.instance ), vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange) diff --git a/packages/core/src/codewhisperer/models/constants.ts b/packages/core/src/codewhisperer/models/constants.ts index c1a9a5445a4..89f19609e7f 100644 --- a/packages/core/src/codewhisperer/models/constants.ts +++ b/packages/core/src/codewhisperer/models/constants.ts @@ -258,6 +258,12 @@ export const securityScanLanguageIds = [ 'c', 'cpp', 'php', + 'xml', + 'toml', + 'pip-requirements', + 'java-properties', + 'go.mod', + 'go.sum', ] as const export type SecurityScanLanguageId = (typeof securityScanLanguageIds)[number] diff --git a/packages/core/src/codewhisperer/util/securityScanLanguageContext.ts b/packages/core/src/codewhisperer/util/securityScanLanguageContext.ts index 9a65e77a88a..466a558a2eb 100644 --- a/packages/core/src/codewhisperer/util/securityScanLanguageContext.ts +++ b/packages/core/src/codewhisperer/util/securityScanLanguageContext.ts @@ -34,6 +34,12 @@ export class SecurityScanLanguageContext { c: 'c', cpp: 'cpp', php: 'php', + xml: 'plaintext', // xml does not exist in CodewhispererLanguage + toml: 'plaintext', + 'pip-requirements': 'plaintext', + 'java-properties': 'plaintext', + 'go.mod': 'plaintext', + 'go.sum': 'plaintext', }) }