Skip to content

Commit ffc499b

Browse files
authored
[CodeWhisperer] Add reference URL in the CWSPR reference panel if present (#3244)
1 parent f6d894d commit ffc499b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/toolwindow/CodeWhispererCodeReferenceComponents.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,32 @@ class CodeWhispererCodeReferenceComponents(private val project: Project) {
6464
BrowserUtil.browse(CodeWhispererLicenseInfoManager.getInstance().getLicenseLink(licenseName))
6565
}.asCodeReferencePanelFont()
6666

67+
private fun repoNameLink(repo: String, url: String) = ActionLink(repo) {
68+
BrowserUtil.browse(url)
69+
}.asCodeReferencePanelFont()
70+
6771
private fun acceptRecommendationSuffixText(repo: String, path: String?, line: String) = JLabel().apply {
6872
val choice = if (path != null) 1 else 0
69-
text = message("codewhisperer.toolwindow.entry.suffix", repo, path ?: "", choice, line)
73+
text = message("codewhisperer.toolwindow.entry.suffix", path ?: "", choice, line)
7074
}.asCodeReferencePanelFont()
7175

7276
fun codeReferenceRecordPanel(ref: Reference, relativePath: String?, lineNums: String) = JPanel(GridBagLayout()).apply {
7377
background = EditorColorsManager.getInstance().globalScheme.defaultBackground
7478
border = BorderFactory.createEmptyBorder(5, 0, 0, 0)
7579
add(acceptRecommendationPrefixText, inlineLabelConstraints)
76-
add(licenseNameLink(ref.licenseName()), inlineLabelConstraints)
77-
add(JLabel(" ").asCodeReferencePanelFont(), inlineLabelConstraints)
80+
81+
// if url to source package/repo is missing, the UX remains the same as we have for now
82+
// if url to source package/repo is present, the url pointing to the source will be present and remove the hyperlink to SPDX
83+
if (ref.url().isNullOrEmpty()) {
84+
add(licenseNameLink(ref.licenseName()), inlineLabelConstraints)
85+
add(JLabel(" from ").asCodeReferencePanelFont(), inlineLabelConstraints)
86+
add(JLabel(ref.repository()), inlineLabelConstraints)
87+
} else {
88+
add(JLabel(ref.licenseName()), inlineLabelConstraints)
89+
add(JLabel(" from ").asCodeReferencePanelFont(), inlineLabelConstraints)
90+
add(repoNameLink(ref.repository(), ref.url()), inlineLabelConstraints)
91+
}
92+
7893
add(acceptRecommendationSuffixText(ref.repository(), relativePath, lineNums), inlineLabelConstraints)
7994
addHorizontalGlue()
8095
}

resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ codewhisperer.settings.show.label=Show CodeWhisperer Settings
311311
codewhisperer.statusbar.display_name=CodeWhisperer
312312
codewhisperer.statusbar.tooltip=CodeWhisperer status
313313
codewhisperer.toolwindow.entry.prefix=[{0}] ACCEPTED recommendation with the following code provided with reference under
314-
codewhisperer.toolwindow.entry.suffix=from repository {0}{2, choice, 0#|1#. Added to {1}} at line {3}
314+
codewhisperer.toolwindow.entry.suffix= {1, choice, 0#|1#. Added to {0}} at line {2}
315315
codewhisperer.toolwindow.popup.text=Reference code under the {0} license from repository {1}
316316
codewhisperer.toolwindow.settings=CodeWhisperer Settings
317317
codewhisperer.toolwindow.settings.prefix=Don't want suggestions that include code with references? Edit in

0 commit comments

Comments
 (0)