Skip to content

Commit

Permalink
fix(amazonq): update security scan languages (aws#5523)
Browse files Browse the repository at this point in the history
## 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.

---

<!--- REMINDER: Ensure that your PR meets the guidelines in
CONTRIBUTING.md -->

License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.
  • Loading branch information
ctlai95 authored Aug 30, 2024
1 parent 5073cc8 commit 2c8d666
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/codewhisperer/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ export async function activate(context: ExtContext): Promise<void> {
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)
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
}

Expand Down

0 comments on commit 2c8d666

Please sign in to comment.