Skip to content

Commit 79bf347

Browse files
committed
more code
1 parent 0a43005 commit 79bf347

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/core/src/codewhisperer/commands/onInlineAcceptance.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { RecommendationService } from '../service/recommendationService'
3232
import { Container } from '../service/serviceContainer'
3333
import { telemetry } from '../../shared/telemetry'
3434
import { TelemetryHelper } from '../util/telemetryHelper'
35+
import { QCodeGenTracker } from '../tracker/qCodeGenTracker'
3536

3637
export const acceptSuggestion = Commands.declare(
3738
'aws.amazonq.accept',
@@ -126,6 +127,7 @@ export async function onInlineAcceptance(acceptanceEntry: OnRecommendationAccept
126127
acceptanceEntry.editor.document.getText(insertedCoderange),
127128
acceptanceEntry.editor.document.fileName
128129
)
130+
QCodeGenTracker.instance.onInlineCompletionAcceptance(acceptanceEntry)
129131
if (acceptanceEntry.references !== undefined) {
130132
const referenceLog = ReferenceLogViewProvider.getReferenceLog(
131133
acceptanceEntry.recommendation,

packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as vscode from 'vscode'
77
import { getLogger } from '../../shared/logger/logger'
88
import * as CodeWhispererConstants from '../models/constants'
9-
import { vsCodeState } from '../models/model'
9+
import { OnRecommendationAcceptanceEntry, vsCodeState } from '../models/model'
1010
import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
1111
import { TelemetryHelper } from '../util/telemetryHelper'
1212
import { AuthUtil } from '../util/authUtil'
@@ -45,6 +45,8 @@ export class QCodeGenTracker {
4545
return TelemetryHelper.instance.isTelemetryEnabled() && AuthUtil.instance.isConnected()
4646
}
4747

48+
// this should be invoked whenever there is a successful Q feature invocation
49+
// for all Q features
4850
public onQFeatureInvoked() {
4951
this._serviceInvocationCount += 1
5052
}
@@ -128,6 +130,10 @@ export class QCodeGenTracker {
128130
}
129131
}
130132

133+
private countNewLines(str: string) {
134+
return str.split('\n').length - 1
135+
}
136+
131137
public onTextDocumentChange(e: vscode.TextDocumentChangeEvent) {
132138
if (
133139
!runtimeLanguageContext.isLanguageSupported(e.document.languageId) ||
@@ -143,8 +149,42 @@ export class QCodeGenTracker {
143149
return
144150
}
145151
this._totalNewCodeCharacterCount += contentChange.text.length
146-
this._totalNewCodeLineCount += contentChange.text.split('\n').length - 1
152+
this._totalNewCodeLineCount += this.countNewLines(contentChange.text)
147153
// start 5 min data reporting once valid user input is detected
148154
this.tryStartTimer()
149155
}
156+
157+
// add Q inline completion contributed code to total code written
158+
public onInlineCompletionAcceptance(acceptanceEntry: OnRecommendationAcceptanceEntry) {
159+
let typeaheadLength = 0
160+
if (acceptanceEntry.editor) {
161+
typeaheadLength = acceptanceEntry.editor.document.getText(acceptanceEntry.range).length
162+
}
163+
const documentChangeLength = acceptanceEntry.recommendation.length - typeaheadLength
164+
// if the inline completion is less than 50 characters, it will be auto captured by onTextDocumentChange
165+
// notice that the document change event of such acceptance do not include typeahead
166+
if (documentChangeLength <= QCodeGenTracker.copySnippetThreshold) {
167+
return
168+
}
169+
this._totalNewCodeCharacterCount += acceptanceEntry.recommendation.length
170+
this._totalNewCodeLineCount += this.countNewLines(acceptanceEntry.recommendation)
171+
}
172+
173+
// add Q chat insert to cursor code to total code written
174+
public onQChatInsertion() {}
175+
176+
// add Q inline chat acceptance to total code written
177+
public onInlineChat() {}
178+
179+
// add Q inline chat acceptance to total code written
180+
public onTransformAcceptance() {}
181+
182+
// add Q feature dev acceptance to total code written
183+
public onFeatureDevAcceptance() {}
184+
185+
// add Q UTG acceptance to total code written
186+
public onUtgAcceptance() {}
187+
188+
// add Q UTG acceptance to total code written
189+
public onDocAcceptance() {}
150190
}

0 commit comments

Comments
 (0)