Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "/review: show code diff for fix preview"
}
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will need this soon, but it probably won't work with the diff view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can add it back once it is needed.

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