Skip to content

Commit ce5e05b

Browse files
authored
feat(amazonq): automatically scroll to fix section (#6210)
## Problem Code fix section is not automatically visible after clicking on generate fix inside code issue detail view. ## Solution - Changed the behavior of updating the webview so that it doesn't close/reopen a new panel every time - Added event listeners to trigger UI updates - Added scroll into view functionality --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b7825d9 commit ce5e05b

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed
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/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)