Skip to content

Commit

Permalink
feat(amazonq): show code diff instead of only code fix for fix preview
Browse files Browse the repository at this point in the history
### Problem
We currently see only code fix for fix preview. We want to see the diff containing both code fix and original code.

### Solution
Remove logic to generate only the code fix.

Remove logic for line number as it will be different for the diff.
  • Loading branch information
atonaamz authored Mar 11, 2025
1 parent 4c190f4 commit 27a698f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "/review: show code diff for fix preview"
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ export class SecurityIssueHoverProvider implements vscode.HoverProvider {
* @returns The markdown string
*/
private _makeCodeBlock(code: string, language?: string) {
const lines = code.replaceAll('\n\\ No newline at end of file', '').split('\n')
const lines = code
.replaceAll('\n\\ No newline at end of file', '')
.replaceAll('--- buggyCode\n', '')
.replaceAll('+++ fixCode\n', '')
.split('\n')
const maxLineChars = lines.reduce((acc, curr) => Math.max(acc, curr.length), 0)
const paddedLines = lines.map((line) => line.padEnd(maxLineChars + 2))

Expand Down
24 changes: 3 additions & 21 deletions packages/core/src/codewhisperer/views/securityIssue/vue/root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import highSeverity from '../../../../../resources/images/severity-high.svg'
import criticalSeverity from '../../../../../resources/images/severity-critical.svg'
import markdownIt from 'markdown-it'
import hljs from 'highlight.js'
import { parsePatch } from 'diff'
import { CodeScanIssue } from '../../../models/model'
const client = WebviewClientFactory.create<SecurityIssueWebview>()
Expand Down Expand Up @@ -344,28 +343,11 @@ export default defineComponent({
if (!this.isFixAvailable) {
return
}
const [parsedDiff] = parsePatch(this.suggestedFix)
const { oldStart } = parsedDiff.hunks[0]
const [referenceStart, referenceEnd] = this.referenceSpan
const htmlString = md.render(`
\`\`\`${this.languageId} showLineNumbers startFrom=${oldStart} ${
referenceStart && referenceEnd
? `highlightStart=${referenceStart + 1} highlightEnd=${referenceEnd + 1}`
: ''
}
${this.fixedCode}
return md.render(`
\`\`\`${this.languageId}
${this.suggestedFix.replaceAll('--- buggyCode\n', '').replaceAll('+++ fixCode\n', '')}
\`\`\`
`)
const parser = new DOMParser()
const doc = parser.parseFromString(htmlString, 'text/html')
const referenceTracker = doc.querySelector('.reference-tracker')
if (referenceTracker) {
const tooltip = doc.createElement('div')
tooltip.classList.add('tooltip')
tooltip.innerHTML = this.referenceText
referenceTracker.appendChild(tooltip)
}
return doc.body.innerHTML
},
scrollTo(refName: string) {
this.$nextTick(() => this.$refs?.[refName]?.scrollIntoView({ behavior: 'smooth' }))
Expand Down

0 comments on commit 27a698f

Please sign in to comment.