Skip to content

Commit ef1163a

Browse files
authored
feat(codewhisperer): show repo url in reference tracker #2803
1 parent d619645 commit ef1163a

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
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": "CodeWhisperer: References include a link to the source repository if possible."
4+
}

src/codewhisperer/service/referenceLogViewProvider.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export class ReferenceLogViewProvider implements vscode.WebviewViewProvider {
7272
editor.document.positionAt(
7373
TelemetryHelper.instance.cursorOffset + reference.recommendationContentSpan.end - 1
7474
).line + 1
75-
const license = `<a href=${LicenseUtil.getLicenseHtml(reference.licenseName)}>${reference.licenseName}</a>`
7675
let lineInfo = ``
7776
if (firstCharLineNumber === lastCharLineNumber) {
7877
lineInfo = `(line at ${firstCharLineNumber})`
@@ -82,7 +81,14 @@ export class ReferenceLogViewProvider implements vscode.WebviewViewProvider {
8281
if (text != ``) {
8382
text += `And `
8483
}
85-
const repository = reference.repository != undefined ? reference.repository : 'unknown'
84+
85+
let license = `<a href=${LicenseUtil.getLicenseHtml(reference.licenseName)}>${reference.licenseName}</a>`
86+
let repository = reference.repository?.length ? reference.repository : 'unknown'
87+
if (reference.url?.length) {
88+
repository = `<a href=${reference.url}>${reference.repository}</a>`
89+
license = reference.licenseName || 'unknown'
90+
}
91+
8692
text +=
8793
CodeWhispererConstants.referenceLogText(
8894
`<br><code>${code}</code><br>`,

src/test/codewhisperer/service/referenceLogViewProvider.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import * as assert from 'assert'
66
import { createMockTextEditor, resetCodeWhispererGlobalVariables } from '../testUtil'
77
import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
8+
import { LicenseUtil } from '../../../codewhisperer/util/licenseUtil'
89

910
describe('referenceLogViewProvider', function () {
1011
beforeEach(function () {
1112
resetCodeWhispererGlobalVariables()
1213
})
1314
describe('getReferenceLog', async function () {
14-
it('Should return expected reference log string', function () {
15+
it('Should return expected reference log string with link to license if there is no url', function () {
1516
const currentTime = new Date()
1617
const currentTimeString = currentTime.toLocaleString()
1718
currentTime.setSeconds(currentTime.getSeconds() + 1)
@@ -34,6 +35,36 @@ describe('referenceLogViewProvider', function () {
3435
assert.ok(actualTime === currentTimeString || actualTime === nextTimeString)
3536
assert.ok(actual.includes('MIT'))
3637
assert.ok(actual.includes('def two_su'))
38+
assert.ok(actual.includes(LicenseUtil.getLicenseHtml('MIT')))
39+
})
40+
41+
it('Should return expected reference log string with link to the repo url if present', function () {
42+
const currentTime = new Date()
43+
const currentTimeString = currentTime.toLocaleString()
44+
currentTime.setSeconds(currentTime.getSeconds() + 1)
45+
const nextTimeString = currentTime.toLocaleString()
46+
const mockEditor = createMockTextEditor()
47+
const recommendation = `def two_sum(nums, target):`
48+
const mockUrl = 'https://www.amazon.com'
49+
const fakeReferences = [
50+
{
51+
message: '',
52+
licenseName: 'MIT',
53+
repository: 'TEST_REPO',
54+
url: mockUrl,
55+
recommendationContentSpan: {
56+
start: 0,
57+
end: 10,
58+
},
59+
},
60+
]
61+
const actual = ReferenceLogViewProvider.getReferenceLog(recommendation, fakeReferences, mockEditor)
62+
const actualTime = actual.substring(1, actual.indexOf(']'))
63+
assert.ok(actualTime === currentTimeString || actualTime === nextTimeString)
64+
assert.ok(actual.includes('MIT'))
65+
assert.ok(actual.includes('def two_su'))
66+
assert.ok(actual.includes(mockUrl))
67+
assert.ok(!actual.includes(LicenseUtil.getLicenseHtml('MIT')))
3768
})
3869
})
3970
})

0 commit comments

Comments
 (0)