@@ -6,6 +6,7 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.codescan.listener
6
6
import com.intellij.icons.AllIcons
7
7
import com.intellij.ide.BrowserUtil
8
8
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI
9
+ import com.intellij.openapi.application.ApplicationManager
9
10
import com.intellij.openapi.command.WriteCommandAction
10
11
import com.intellij.openapi.editor.event.EditorMouseEvent
11
12
import com.intellij.openapi.editor.event.EditorMouseEventArea
@@ -19,13 +20,18 @@ import com.intellij.ui.JBColor
19
20
import com.intellij.ui.awt.RelativePoint
20
21
import com.intellij.ui.components.JBScrollPane
21
22
import icons.AwsIcons
23
+ import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException
22
24
import software.aws.toolkits.core.utils.debug
23
25
import software.aws.toolkits.core.utils.error
24
26
import software.aws.toolkits.core.utils.getLogger
25
27
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanIssue
26
28
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanManager
29
+ import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererClientAdaptor
30
+ import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage
31
+ import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
27
32
import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhispererTelemetryService
28
33
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererColorUtil.getHexString
34
+ import software.aws.toolkits.jetbrains.services.codewhisperer.util.runIfIdcConnectionOrTelemetryEnabled
29
35
import software.aws.toolkits.jetbrains.utils.applyPatch
30
36
import software.aws.toolkits.jetbrains.utils.convertMarkdownToHTML
31
37
import software.aws.toolkits.jetbrains.utils.notifyError
@@ -95,7 +101,7 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
95
101
<tbody>
96
102
<tr>
97
103
<td>$cweLinks </td>
98
- <td>${if (isFixAvailable) " <span style=\" color:${additionForegroundColor.getHexString()} ;\" >Yes</span>" else " <span style=\" color:${deletionForegroundColor.getHexString()} ;\" >No</span>" } </td>
104
+ <td>${if (isFixAvailable) " <span style=\" color:${additionForegroundColor.getHexString()} ;\" >Yes</span>" else " <span style=\" color:${deletionForegroundColor.getHexString()} ;\" >No</span>" } </td>
99
105
<td>$detectorLibraryLink </td>
100
106
</tr>
101
107
</tbody>
@@ -115,13 +121,17 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
115
121
|${issue.suggestedFixes[0 ].code}
116
122
|```
117
123
|
118
- |${if (isFixDescriptionAvailable) {
119
- " |### ${message(
120
- " codewhisperer.codescan.suggested_fix_description"
121
- )} \n ${issue.suggestedFixes[0 ].description} "
122
- } else {
123
- " "
124
- }}
124
+ |${
125
+ if (isFixDescriptionAvailable) {
126
+ " |### ${
127
+ message(
128
+ " codewhisperer.codescan.suggested_fix_description"
129
+ )
130
+ } \n ${issue.suggestedFixes[0 ].description} "
131
+ } else {
132
+ " "
133
+ }
134
+ }
125
135
""" .trimMargin()
126
136
} else {
127
137
" "
@@ -253,6 +263,54 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
253
263
popup.show(RelativePoint (e.mouseEvent))
254
264
255
265
CodeWhispererTelemetryService .getInstance().sendCodeScanIssueHoverEvent(issue)
266
+ sendCodeRemediationTelemetryToServiceApi(
267
+ issue.file.programmingLanguage(),
268
+ " CODESCAN_ISSUE_HOVER" ,
269
+ issue.detectorId,
270
+ issue.findingId,
271
+ issue.ruleId,
272
+ null ,
273
+ null ,
274
+ null ,
275
+ issue.suggestedFixes.isNotEmpty()
276
+ )
277
+ }
278
+
279
+ private fun sendCodeRemediationTelemetryToServiceApi (
280
+ language : CodeWhispererProgrammingLanguage ? ,
281
+ codeScanRemediationEventType : String? ,
282
+ detectorId : String? ,
283
+ findingId : String? ,
284
+ ruleId : String? ,
285
+ component : String? ,
286
+ reason : String? ,
287
+ result : String? ,
288
+ includesFix : Boolean?
289
+ ) {
290
+ runIfIdcConnectionOrTelemetryEnabled(project) {
291
+ ApplicationManager .getApplication().executeOnPooledThread {
292
+ try {
293
+ val response = CodeWhispererClientAdaptor .getInstance(project)
294
+ .sendCodeScanRemediationTelemetry(
295
+ language,
296
+ codeScanRemediationEventType,
297
+ detectorId,
298
+ findingId,
299
+ ruleId,
300
+ component,
301
+ reason,
302
+ result,
303
+ includesFix
304
+ )
305
+ LOG .debug { " Successfully sent code scan remediation telemetry. RequestId: ${response.responseMetadata().requestId()} " }
306
+ } catch (e: Exception ) {
307
+ val requestId = if (e is CodeWhispererRuntimeException ) e.requestId() else null
308
+ LOG .debug {
309
+ " Failed to send code scan remediation telemetry. RequestId: $requestId , ErrorMessage: ${e.message} "
310
+ }
311
+ }
312
+ }
313
+ }
256
314
}
257
315
258
316
override fun mouseMoved (e : EditorMouseEvent ) {
@@ -305,10 +363,32 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
305
363
CodeWhispererTelemetryService .getInstance().sendCodeScanIssueApplyFixEvent(issue, Result .Succeeded )
306
364
hidePopup()
307
365
}
366
+ sendCodeRemediationTelemetryToServiceApi(
367
+ issue.file.programmingLanguage(),
368
+ " CODESCAN_ISSUE_APPLY_FIX" ,
369
+ issue.detectorId,
370
+ issue.findingId,
371
+ issue.ruleId,
372
+ null ,
373
+ null ,
374
+ Result .Succeeded .toString(),
375
+ issue.suggestedFixes.isNotEmpty()
376
+ )
308
377
} catch (err: Error ) {
309
378
notifyError(message(" codewhisperer.codescan.fix_applied_fail" , err))
310
379
LOG .error { " Apply fix command failed. $err " }
311
380
CodeWhispererTelemetryService .getInstance().sendCodeScanIssueApplyFixEvent(issue, Result .Failed , err.message)
381
+ sendCodeRemediationTelemetryToServiceApi(
382
+ issue.file.programmingLanguage(),
383
+ " CODESCAN_ISSUE_APPLY_FIX" ,
384
+ issue.detectorId,
385
+ issue.findingId,
386
+ issue.ruleId,
387
+ null ,
388
+ err.message,
389
+ Result .Failed .toString(),
390
+ issue.suggestedFixes.isNotEmpty()
391
+ )
312
392
}
313
393
}
314
394
}
0 commit comments