Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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": "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')
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
Loading