@@ -64,6 +64,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeCove
6464import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhispererCodeCoverageTracker
6565import software.aws.toolkits.jetbrains.services.codewhisperer.toolwindow.CodeWhispererCodeReferenceManager
6666import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.TOTAL_SECONDS_IN_MINUTE
67+ import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererUtil.getUnmodifiedAcceptedCharsCount
6768import software.aws.toolkits.jetbrains.services.codewhisperer.util.CrossFileStrategy
6869import software.aws.toolkits.jetbrains.services.telemetry.NoOpPublisher
6970import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
@@ -253,7 +254,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
253254 val captor = argumentCaptor<DocumentEvent >()
254255 verify(sut, Times (1 )).documentChanged(captor.capture())
255256 assertThat(captor.firstValue.newFragment.toString()).isEqualTo(keystrokeInput)
256- assertThat(sut.totalTokensSize ).isEqualTo(keystrokeInput.length.toLong())
257+ assertThat(sut.totalCharsCount ).isEqualTo(keystrokeInput.length.toLong())
257258 }
258259
259260 @Test
@@ -271,15 +272,15 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
271272 val captor = argumentCaptor<DocumentEvent >()
272273 verify(sut, Times (1 )).documentChanged(captor.capture())
273274 assertThat(captor.firstValue.newFragment.toString()).isEqualTo(pythonTestLeftContext)
274- assertThat(sut.totalTokensSize ).isEqualTo(pythonTestLeftContext.length.toLong())
275+ assertThat(sut.totalCharsCount ).isEqualTo(pythonTestLeftContext.length.toLong())
275276
276277 val anotherCode = " (x, y):" .repeat(8 )
277278 runInEdtAndWait {
278279 WriteCommandAction .runWriteCommandAction(project) {
279280 fixture.editor.appendString(anotherCode)
280281 }
281282 }
282- assertThat(sut.totalTokensSize ).isEqualTo(pythonTestLeftContext.length.toLong())
283+ assertThat(sut.totalCharsCount ).isEqualTo(pythonTestLeftContext.length.toLong())
283284 }
284285
285286 @Test
@@ -293,7 +294,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
293294
294295 CodeWhispererCodeCoverageTracker .getInstancesMap()[CodeWhispererPython .INSTANCE ] = sut
295296 sut.activateTrackerIfNotActive()
296- assertThat(sut.totalTokensSize ).isEqualTo(pythonTestLeftContext.length.toLong())
297+ assertThat(sut.totalCharsCount ).isEqualTo(pythonTestLeftContext.length.toLong())
297298
298299 runInEdtAndWait {
299300 fixture.editor.caretModel.primaryCaret.moveToOffset(fixture.editor.document.textLength)
@@ -302,7 +303,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
302303 }
303304 }
304305
305- assertThat(sut.totalTokensSize ).isEqualTo(pythonTestLeftContext.length.toLong())
306+ assertThat(sut.totalCharsCount ).isEqualTo(pythonTestLeftContext.length.toLong())
306307 }
307308
308309 @Test
@@ -315,15 +316,15 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
315316 )
316317 CodeWhispererCodeCoverageTracker .getInstancesMap()[CodeWhispererPython .INSTANCE ] = sut
317318 sut.activateTrackerIfNotActive()
318- assertThat(sut.totalTokensSize ).isEqualTo(pythonTestLeftContext.length.toLong())
319+ assertThat(sut.totalCharsCount ).isEqualTo(pythonTestLeftContext.length.toLong())
319320
320321 runInEdtAndWait {
321322 WriteCommandAction .runWriteCommandAction(project) {
322323 fixture.editor.document.insertString(fixture.editor.caretModel.offset, " \t " )
323324 }
324325 }
325326
326- assertThat(sut.totalTokensSize ).isEqualTo(pythonTestLeftContext.length + 1L )
327+ assertThat(sut.totalCharsCount ).isEqualTo(pythonTestLeftContext.length + 1L )
327328 }
328329
329330 @Test
@@ -366,36 +367,14 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
366367
367368 sut.activateTrackerIfNotActive()
368369 assertThat(sut.activeRequestCount()).isEqualTo(1 )
369- assertThat(sut.acceptedTokensSize ).isEqualTo(" bar" .length.toLong())
370- assertThat(sut.totalTokensSize ).isEqualTo(" foobar" .length.toLong())
370+ assertThat(sut.unmodifiedAcceptedCharsCount ).isEqualTo(" bar" .length.toLong())
371+ assertThat(sut.totalCharsCount ).isEqualTo(" foobar" .length.toLong())
371372
372373 sut.forceTrackerFlush()
373374
374375 assertThat(sut.activeRequestCount()).isEqualTo(1 )
375- assertThat(sut.acceptedTokensSize).isEqualTo(0 )
376- assertThat(sut.totalTokensSize).isEqualTo(0 )
377- }
378-
379- @Test
380- fun `test when rangeMarker is not vaild, acceptedToken will not be updated` () {
381- // when user delete whole recommendation, rangeMarker will be isValid = false
382- val rangeMarkerMock: RangeMarker = mock()
383- whenever(rangeMarkerMock.isValid).thenReturn(false )
384- sut = spy(
385- TestCodePercentageTracker (
386- project,
387- TOTAL_SECONDS_IN_MINUTE ,
388- CodeWhispererPython .INSTANCE ,
389- mutableListOf (rangeMarkerMock),
390- )
391- ) {
392- onGeneric { getUnmodifiedAcceptedCharsCount(any(), any()) } doReturn 100
393- }
394-
395- sut.activateTrackerIfNotActive()
396- sut.forceTrackerFlush()
397-
398- verify(sut, Times (0 )).getUnmodifiedAcceptedCharsCount(any(), any())
376+ assertThat(sut.unmodifiedAcceptedCharsCount).isEqualTo(0 )
377+ assertThat(sut.totalCharsCount).isEqualTo(0 )
399378 }
400379
401380 @Test
@@ -430,12 +409,11 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
430409 TOTAL_SECONDS_IN_MINUTE ,
431410 CodeWhispererPython .INSTANCE ,
432411 mutableListOf (rangeMarkerMock1),
433- mutableMapOf (fixture.editor.document to CodeCoverageTokens (totalTokens = 100 , acceptedTokens = 0 , rawAcceptedTokens = 0 )),
412+ mutableMapOf (fixture.editor.document to CodeCoverageTokens (totalChars = 100 , unmodifiedAcceptedChars = 0 , acceptedChars = 0 )),
434413 1
435414 )
436415 ) {
437416 onGeneric { extractRangeMarkerString(any()) } doReturn " fou"
438- onGeneric { getUnmodifiedAcceptedCharsCount(any(), any()) } doReturn 1
439417 }
440418 sut.emitCodeWhispererCodeContribution()
441419
@@ -445,8 +423,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
445423 metricCaptor.allValues,
446424 CODE_PERCENTAGE ,
447425 1 ,
448- CWSPR_PERCENTAGE to " 3" ,
449- CWSPR_ACCEPTED_TOKENS to " 1" ,
426+ CWSPR_ACCEPTED_TOKENS to " 2" ,
450427 CWSPR_RAW_ACCEPTED_TOKENS to " 3" ,
451428 CWSPR_TOTAL_TOKENS to " 100" ,
452429 )
@@ -465,48 +442,47 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
465442 }
466443
467444 @Test
468- fun `test getAcceptedTokensDelta()` () {
469- val tracker = TestCodePercentageTracker (project, TOTAL_SECONDS_IN_MINUTE , CodeWhispererPython .INSTANCE )
445+ fun `test getUnmodifiedAcceptedCharsCount()` () {
470446 var originalRecommendation = " foo"
471447 var modifiedRecommendation = " fou"
472- var delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
473- assertThat(delta ).isEqualTo(2 )
448+ var unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
449+ assertThat(unmodifiedCharsCount ).isEqualTo(2 )
474450
475451 originalRecommendation = " foo"
476452 modifiedRecommendation = " f11111oo"
477- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
478- assertThat(delta ).isEqualTo(3 )
453+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
454+ assertThat(unmodifiedCharsCount ).isEqualTo(3 )
479455
480456 originalRecommendation = " foo"
481457 modifiedRecommendation = " fo"
482- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
483- assertThat(delta ).isEqualTo(2 )
458+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
459+ assertThat(unmodifiedCharsCount ).isEqualTo(2 )
484460
485461 originalRecommendation = " helloworld"
486462 modifiedRecommendation = " HelloWorld"
487- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
488- assertThat(delta ).isEqualTo(" helloworld" .length - 2 )
463+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
464+ assertThat(unmodifiedCharsCount ).isEqualTo(" helloworld" .length - 2 )
489465
490466 originalRecommendation = " helloworld"
491467 modifiedRecommendation = " World"
492- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
493- assertThat(delta ).isEqualTo(" helloworld" .length - " hello" .length - 1 )
468+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
469+ assertThat(unmodifiedCharsCount ).isEqualTo(" helloworld" .length - " hello" .length - 1 )
494470
495471 originalRecommendation = " CodeWhisperer"
496472 modifiedRecommendation = " CODE"
497- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
498- assertThat(delta ).isEqualTo(1 )
473+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
474+ assertThat(unmodifiedCharsCount ).isEqualTo(1 )
499475
500476 originalRecommendation = " CodeWhisperer"
501477 modifiedRecommendation = " codewhispererISBEST"
502- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
503- assertThat(delta ).isEqualTo(" CodeWhisperer" .length - 2 )
478+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
479+ assertThat(unmodifiedCharsCount ).isEqualTo(" CodeWhisperer" .length - 2 )
504480
505481 val pythonCommentAddedByUser = " \"\"\" we don't count this comment as generated by CodeWhisperer\"\"\"\n "
506482 originalRecommendation = " x, y):\n\t return x + y"
507483 modifiedRecommendation = " x, y):\n $pythonCommentAddedByUser \t return x + y"
508- delta = tracker. getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
509- assertThat(delta ).isEqualTo(originalRecommendation.length)
484+ unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
485+ assertThat(unmodifiedCharsCount ).isEqualTo(originalRecommendation.length)
510486 }
511487
512488 @Test
@@ -557,7 +533,7 @@ internal class CodeWhispererCodeCoverageTrackerTestJava : CodeWhispererCodeCover
557533 project,
558534 TOTAL_SECONDS_IN_MINUTE ,
559535 language = CodeWhispererJava .INSTANCE ,
560- codeCoverageTokens = mutableMapOf (fixture.editor.document to CodeCoverageTokens (totalTokens = codeNeedToBeReformatted.length))
536+ codeCoverageTokens = mutableMapOf (fixture.editor.document to CodeCoverageTokens (totalChars = codeNeedToBeReformatted.length))
561537 )
562538 )
563539 CodeWhispererCodeCoverageTracker .getInstancesMap()[CodeWhispererJava .INSTANCE ] = sut
@@ -568,7 +544,7 @@ internal class CodeWhispererCodeCoverageTrackerTestJava : CodeWhispererCodeCover
568544 }
569545 // reformat should fire documentChanged events, but tracker should not update token from these events
570546 verify(sut, atLeastOnce()).documentChanged(any())
571- assertThat(sut.totalTokensSize ).isEqualTo(codeNeedToBeReformatted.length.toLong())
547+ assertThat(sut.totalCharsCount ).isEqualTo(codeNeedToBeReformatted.length.toLong())
572548
573549 val formatted = """
574550 class Answer {
0 commit comments