Skip to content

Commit 86a6e6e

Browse files
Merge master into feature/amazonqLSP
2 parents 3b2dc5f + ce5e05b commit 86a6e6e

File tree

6 files changed

+67
-16
lines changed

6 files changed

+67
-16
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "/review: Diagnostics in the problems panel are mapped to the wrong code"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "/review: Code fix automatically scrolls into view after generation."
4+
}

packages/amazonq/test/unit/codewhisperer/service/diagnosticsProvider.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
removeDiagnostic,
1313
disposeSecurityDiagnostic,
1414
SecurityDiagnostic,
15+
createSecurityDiagnostic,
16+
codewhispererDiagnosticSourceLabel,
1517
} from 'aws-core-vscode/codewhisperer'
1618
import { createCodeScanIssue, createMockDocument, createTextDocumentChangeEvent } from 'aws-core-vscode/test'
1719

@@ -83,4 +85,16 @@ describe('diagnosticsProvider', function () {
8385
assert.strictEqual(actual[1].range.start.line, 5)
8486
assert.strictEqual(actual[1].range.end.line, 6)
8587
})
88+
89+
it('should create securityDiagnostic from codeScanIssue', function () {
90+
const codeScanIssue = createCodeScanIssue()
91+
const securityDiagnostic = createSecurityDiagnostic(codeScanIssue)
92+
assert.strictEqual(securityDiagnostic.findingId, codeScanIssue.findingId)
93+
assert.strictEqual(securityDiagnostic.message, codeScanIssue.title)
94+
assert.strictEqual(securityDiagnostic.range.start.line, codeScanIssue.startLine)
95+
assert.strictEqual(securityDiagnostic.range.end.line, codeScanIssue.endLine)
96+
assert.strictEqual(securityDiagnostic.severity, vscode.DiagnosticSeverity.Warning)
97+
assert.strictEqual(securityDiagnostic.source, codewhispererDiagnosticSourceLabel)
98+
assert.strictEqual(securityDiagnostic.code, codeScanIssue.ruleId)
99+
})
86100
})

packages/core/src/codewhisperer/service/diagnosticsProvider.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ export function createSecurityDiagnostic(securityIssue: CodeScanIssue) {
7474
vscode.DiagnosticSeverity.Warning
7575
)
7676
securityDiagnostic.source = codewhispererDiagnosticSourceLabel
77-
// const detectorUrl = securityIssue.recommendation.url
78-
securityDiagnostic.code = securityIssue.findingId
79-
// securityDiagnostic.code = detectorUrl
80-
// ? {
81-
// value: securityIssue.detectorId,
82-
// target: vscode.Uri.parse(detectorUrl),
83-
// }
84-
// : securityIssue.detectorId
77+
securityDiagnostic.code = securityIssue.ruleId
8578
securityDiagnostic.findingId = securityIssue.findingId
8679
return securityDiagnostic
8780
}

packages/core/src/codewhisperer/views/securityIssue/securityIssueWebview.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import { ExtContext } from '../../../shared/extensions'
2424
export class SecurityIssueWebview extends VueWebview {
2525
public static readonly sourcePath: string = 'src/codewhisperer/views/securityIssue/vue/index.js'
2626
public readonly id = 'aws.codeWhisperer.securityIssue'
27+
public readonly onChangeIssue = new vscode.EventEmitter<CodeScanIssue | undefined>()
28+
public readonly onChangeFilePath = new vscode.EventEmitter<string | undefined>()
29+
public readonly onChangeGenerateFixLoading = new vscode.EventEmitter<boolean>()
30+
public readonly onChangeGenerateFixError = new vscode.EventEmitter<boolean>()
2731

2832
private issue: CodeScanIssue | undefined
2933
private filePath: string | undefined
@@ -40,10 +44,12 @@ export class SecurityIssueWebview extends VueWebview {
4044

4145
public setIssue(issue: CodeScanIssue) {
4246
this.issue = issue
47+
this.onChangeIssue.fire(issue)
4348
}
4449

4550
public setFilePath(filePath: string) {
4651
this.filePath = filePath
52+
this.onChangeFilePath.fire(filePath)
4753
}
4854

4955
public applyFix() {
@@ -90,6 +96,7 @@ export class SecurityIssueWebview extends VueWebview {
9096

9197
public setIsGenerateFixLoading(isGenerateFixLoading: boolean) {
9298
this.isGenerateFixLoading = isGenerateFixLoading
99+
this.onChangeGenerateFixLoading.fire(isGenerateFixLoading)
93100
}
94101

95102
public getIsGenerateFixError() {
@@ -98,6 +105,7 @@ export class SecurityIssueWebview extends VueWebview {
98105

99106
public setIsGenerateFixError(isGenerateFixError: boolean) {
100107
this.isGenerateFixError = isGenerateFixError
108+
this.onChangeGenerateFixError.fire(isGenerateFixError)
101109
}
102110

103111
public generateFix() {
@@ -189,12 +197,7 @@ const Panel = VueWebview.compilePanel(SecurityIssueWebview)
189197
let activePanel: InstanceType<typeof Panel> | undefined
190198

191199
export async function showSecurityIssueWebview(ctx: vscode.ExtensionContext, issue: CodeScanIssue, filePath: string) {
192-
const previousPanel = activePanel
193-
const previousId = previousPanel?.server?.getIssue()?.findingId
194-
if (previousPanel && previousId) {
195-
previousPanel.server.closeWebview(previousId)
196-
}
197-
activePanel = new Panel(ctx)
200+
activePanel ??= new Panel(ctx)
198201
activePanel.server.setIssue(issue)
199202
activePanel.server.setFilePath(filePath)
200203
activePanel.server.setIsGenerateFixLoading(false)

packages/core/src/codewhisperer/views/securityIssue/vue/root.vue

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
</div>
4848
</div>
4949

50-
<div v-if="isFixAvailable || isGenerateFixLoading || isGenerateFixError || isFixDescriptionAvailable">
50+
<div
51+
v-if="isFixAvailable || isGenerateFixLoading || isGenerateFixError || isFixDescriptionAvailable"
52+
ref="codeFixSection"
53+
>
5154
<hr />
5255

5356
<h3>Suggested code fix preview</h3>
@@ -57,7 +60,7 @@
5760
</pre>
5861
<div class="code-block">
5962
<span v-if="isFixAvailable" v-html="suggestedFixHtml"></span>
60-
<div v-if="isFixAvailable" class="code-diff-actions">
63+
<div v-if="isFixAvailable" class="code-diff-actions" ref="codeFixAction">
6164
<button class="code-diff-action-button" @click="copyFixedCode">
6265
<span class="icon icon-md icon-vscode-copy"></span> Copy
6366
</button>
@@ -201,6 +204,7 @@ export default defineComponent({
201204
},
202205
created() {
203206
this.getData()
207+
this.setupEventListeners()
204208
},
205209
beforeMount() {
206210
this.getData()
@@ -223,6 +227,32 @@ export default defineComponent({
223227
const fixedCode = await client.getFixedCode()
224228
this.updateFixedCode(fixedCode)
225229
},
230+
setupEventListeners() {
231+
client.onChangeIssue(async (issue) => {
232+
if (issue) {
233+
this.updateFromIssue(issue)
234+
}
235+
const fixedCode = await client.getFixedCode()
236+
this.updateFixedCode(fixedCode)
237+
this.scrollTo('codeFixActions')
238+
})
239+
client.onChangeFilePath(async (filePath) => {
240+
const relativePath = await client.getRelativePath()
241+
this.updateRelativePath(relativePath)
242+
243+
const languageId = await client.getLanguageId()
244+
if (languageId) {
245+
this.updateLanguageId(languageId)
246+
}
247+
})
248+
client.onChangeGenerateFixLoading((isGenerateFixLoading) => {
249+
this.isGenerateFixLoading = isGenerateFixLoading
250+
this.scrollTo('codeFixSection')
251+
})
252+
client.onChangeGenerateFixError((isGenerateFixError) => {
253+
this.isGenerateFixError = isGenerateFixError
254+
})
255+
},
226256
updateRelativePath(relativePath: string) {
227257
this.relativePath = relativePath
228258
},
@@ -339,6 +369,9 @@ ${this.fixedCode}
339369
}
340370
return doc.body.innerHTML
341371
},
372+
scrollTo(refName: string) {
373+
this.$nextTick(() => this.$refs?.[refName]?.scrollIntoView({ behavior: 'smooth' }))
374+
},
342375
},
343376
computed: {
344377
severityImage() {

0 commit comments

Comments
 (0)