Skip to content

Commit

Permalink
use the current document to track range for persistence (#5812)
Browse files Browse the repository at this point in the history
Use the current document for tracking the insertText. Using the
pre-calculated text was making the offline diffs inaccurate, as
introduced in the
[PR](https://github.com/sourcegraph/cody/pull/5767/files).

## Test plan
CI checks
  • Loading branch information
hitesh-1997 committed Oct 4, 2024
1 parent 0d67d14 commit 3d430c9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
2 changes: 0 additions & 2 deletions vscode/src/completions/inline-completion-item-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,6 @@ export class InlineCompletionItemProvider
suggestionEvent.markAsRead({
document: invokedDocument,
position: invokedPosition,
completePrefix: completion.requestParams.docContext.completePrefix,
completeSuffix: completion.requestParams.docContext.completeSuffix,
})
}
}, this.COMPLETION_VISIBLE_DELAY_MS)
Expand Down
8 changes: 0 additions & 8 deletions vscode/src/completions/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ describe('logger', () => {
suggestionEvent?.markAsRead({
document,
position,
completePrefix: defaultRequestParams.docContext.completePrefix,
completeSuffix: defaultRequestParams.docContext.completeSuffix,
})
CompletionLogger.accepted(id, document, item, range(0, 0, 0, 0), false)

Expand Down Expand Up @@ -119,8 +117,6 @@ describe('logger', () => {
firstSuggestionEvent?.markAsRead({
document,
position,
completePrefix: defaultRequestParams.docContext.completePrefix,
completeSuffix: defaultRequestParams.docContext.completeSuffix,
})

const loggerItem = CompletionLogger.getCompletionEvent(id1)
Expand All @@ -142,8 +138,6 @@ describe('logger', () => {
secondSuggestionEvent?.markAsRead({
document,
position,
completePrefix: defaultRequestParams.docContext.completePrefix,
completeSuffix: defaultRequestParams.docContext.completeSuffix,
})
CompletionLogger.accepted(id2, document, item, range(0, 0, 0, 0), false)

Expand Down Expand Up @@ -172,8 +166,6 @@ describe('logger', () => {
thirdSuggestionEvent?.markAsRead({
document,
position,
completePrefix: defaultRequestParams.docContext.completePrefix,
completeSuffix: defaultRequestParams.docContext.completeSuffix,
})

const loggerItem3 = CompletionLogger.getCompletionEvent(id3)
Expand Down
20 changes: 5 additions & 15 deletions vscode/src/completions/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,7 @@ function getInlineContextItemContext(
function suggestionDocumentDiffTracker(
interactionId: CompletionAnalyticsID,
document: vscode.TextDocument,
position: vscode.Position,
completePrefix: string,
completeSuffix: string
position: vscode.Position
): void {
// If user is not in the same document, we don't track the diff.
if (document.uri.scheme !== 'file') {
Expand All @@ -795,12 +793,12 @@ function suggestionDocumentDiffTracker(
Math.min(document.getText().length, document.offsetAt(position) + offsetBytes)
)
const trackingRange = new vscode.Range(startPosition, endPosition)
const documentText = completePrefix.slice(-offsetBytes) + completeSuffix.slice(0, offsetBytes)
const documentText = document.getText(trackingRange)

const persistenceTimeoutList = [
15 * 1000, // 15 seconds
30 * 1000, // 30 seconds
20 * 1000, // 20 seconds
60 * 1000, // 60 seconds
120 * 1000, // 120 seconds
]
persistenceTracker.track({
id: interactionId,
Expand All @@ -820,8 +818,6 @@ function suggestionDocumentDiffTracker(
type SuggestionMarkReadParam = {
document: vscode.TextDocument
position: vscode.Position
completePrefix: string
completeSuffix: string
}

// Suggested completions will not be logged immediately. Instead, we log them when we either hide
Expand Down Expand Up @@ -879,13 +875,7 @@ export function prepareSuggestionEvent({
isDotCom(authStatus.endpoint || '') &&
event.params.inlineCompletionItemContext?.isRepoPublic
) {
suggestionDocumentDiffTracker(
event.params.id,
param.document,
param.position,
param.completePrefix,
param.completeSuffix
)
suggestionDocumentDiffTracker(event.params.id, param.document, param.position)
}
},
}
Expand Down

0 comments on commit 3d430c9

Please sign in to comment.