Skip to content

Commit

Permalink
Merge master into feature/amazonqLSP
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Dec 12, 2024
2 parents 3b2dc5f + ce5e05b commit 86a6e6e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "/review: Diagnostics in the problems panel are mapped to the wrong code"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "/review: Code fix automatically scrolls into view after generation."
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
removeDiagnostic,
disposeSecurityDiagnostic,
SecurityDiagnostic,
createSecurityDiagnostic,
codewhispererDiagnosticSourceLabel,
} from 'aws-core-vscode/codewhisperer'
import { createCodeScanIssue, createMockDocument, createTextDocumentChangeEvent } from 'aws-core-vscode/test'

Expand Down Expand Up @@ -83,4 +85,16 @@ describe('diagnosticsProvider', function () {
assert.strictEqual(actual[1].range.start.line, 5)
assert.strictEqual(actual[1].range.end.line, 6)
})

it('should create securityDiagnostic from codeScanIssue', function () {
const codeScanIssue = createCodeScanIssue()
const securityDiagnostic = createSecurityDiagnostic(codeScanIssue)
assert.strictEqual(securityDiagnostic.findingId, codeScanIssue.findingId)
assert.strictEqual(securityDiagnostic.message, codeScanIssue.title)
assert.strictEqual(securityDiagnostic.range.start.line, codeScanIssue.startLine)
assert.strictEqual(securityDiagnostic.range.end.line, codeScanIssue.endLine)
assert.strictEqual(securityDiagnostic.severity, vscode.DiagnosticSeverity.Warning)
assert.strictEqual(securityDiagnostic.source, codewhispererDiagnosticSourceLabel)
assert.strictEqual(securityDiagnostic.code, codeScanIssue.ruleId)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ export function createSecurityDiagnostic(securityIssue: CodeScanIssue) {
vscode.DiagnosticSeverity.Warning
)
securityDiagnostic.source = codewhispererDiagnosticSourceLabel
// const detectorUrl = securityIssue.recommendation.url
securityDiagnostic.code = securityIssue.findingId
// securityDiagnostic.code = detectorUrl
// ? {
// value: securityIssue.detectorId,
// target: vscode.Uri.parse(detectorUrl),
// }
// : securityIssue.detectorId
securityDiagnostic.code = securityIssue.ruleId
securityDiagnostic.findingId = securityIssue.findingId
return securityDiagnostic
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import { ExtContext } from '../../../shared/extensions'
export class SecurityIssueWebview extends VueWebview {
public static readonly sourcePath: string = 'src/codewhisperer/views/securityIssue/vue/index.js'
public readonly id = 'aws.codeWhisperer.securityIssue'
public readonly onChangeIssue = new vscode.EventEmitter<CodeScanIssue | undefined>()
public readonly onChangeFilePath = new vscode.EventEmitter<string | undefined>()
public readonly onChangeGenerateFixLoading = new vscode.EventEmitter<boolean>()
public readonly onChangeGenerateFixError = new vscode.EventEmitter<boolean>()

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

public setIssue(issue: CodeScanIssue) {
this.issue = issue
this.onChangeIssue.fire(issue)
}

public setFilePath(filePath: string) {
this.filePath = filePath
this.onChangeFilePath.fire(filePath)
}

public applyFix() {
Expand Down Expand Up @@ -90,6 +96,7 @@ export class SecurityIssueWebview extends VueWebview {

public setIsGenerateFixLoading(isGenerateFixLoading: boolean) {
this.isGenerateFixLoading = isGenerateFixLoading
this.onChangeGenerateFixLoading.fire(isGenerateFixLoading)
}

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

public setIsGenerateFixError(isGenerateFixError: boolean) {
this.isGenerateFixError = isGenerateFixError
this.onChangeGenerateFixError.fire(isGenerateFixError)
}

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

export async function showSecurityIssueWebview(ctx: vscode.ExtensionContext, issue: CodeScanIssue, filePath: string) {
const previousPanel = activePanel
const previousId = previousPanel?.server?.getIssue()?.findingId
if (previousPanel && previousId) {
previousPanel.server.closeWebview(previousId)
}
activePanel = new Panel(ctx)
activePanel ??= new Panel(ctx)
activePanel.server.setIssue(issue)
activePanel.server.setFilePath(filePath)
activePanel.server.setIsGenerateFixLoading(false)
Expand Down
37 changes: 35 additions & 2 deletions packages/core/src/codewhisperer/views/securityIssue/vue/root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
</div>
</div>

<div v-if="isFixAvailable || isGenerateFixLoading || isGenerateFixError || isFixDescriptionAvailable">
<div
v-if="isFixAvailable || isGenerateFixLoading || isGenerateFixError || isFixDescriptionAvailable"
ref="codeFixSection"
>
<hr />

<h3>Suggested code fix preview</h3>
Expand All @@ -57,7 +60,7 @@
</pre>
<div class="code-block">
<span v-if="isFixAvailable" v-html="suggestedFixHtml"></span>
<div v-if="isFixAvailable" class="code-diff-actions">
<div v-if="isFixAvailable" class="code-diff-actions" ref="codeFixAction">
<button class="code-diff-action-button" @click="copyFixedCode">
<span class="icon icon-md icon-vscode-copy"></span> Copy
</button>
Expand Down Expand Up @@ -201,6 +204,7 @@ export default defineComponent({
},
created() {
this.getData()
this.setupEventListeners()
},
beforeMount() {
this.getData()
Expand All @@ -223,6 +227,32 @@ export default defineComponent({
const fixedCode = await client.getFixedCode()
this.updateFixedCode(fixedCode)
},
setupEventListeners() {
client.onChangeIssue(async (issue) => {
if (issue) {
this.updateFromIssue(issue)
}
const fixedCode = await client.getFixedCode()
this.updateFixedCode(fixedCode)
this.scrollTo('codeFixActions')
})
client.onChangeFilePath(async (filePath) => {
const relativePath = await client.getRelativePath()
this.updateRelativePath(relativePath)
const languageId = await client.getLanguageId()
if (languageId) {
this.updateLanguageId(languageId)
}
})
client.onChangeGenerateFixLoading((isGenerateFixLoading) => {
this.isGenerateFixLoading = isGenerateFixLoading
this.scrollTo('codeFixSection')
})
client.onChangeGenerateFixError((isGenerateFixError) => {
this.isGenerateFixError = isGenerateFixError
})
},
updateRelativePath(relativePath: string) {
this.relativePath = relativePath
},
Expand Down Expand Up @@ -339,6 +369,9 @@ ${this.fixedCode}
}
return doc.body.innerHTML
},
scrollTo(refName: string) {
this.$nextTick(() => this.$refs?.[refName]?.scrollIntoView({ behavior: 'smooth' }))
},
},
computed: {
severityImage() {
Expand Down

0 comments on commit 86a6e6e

Please sign in to comment.