Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete: Log number of accepted chars per suggestion #674

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

### Changed

- Include the number of accepted characters per autocomplete suggestion. [pull/674](https://github.com/sourcegraph/cody/pull/674)

## [0.6.6]

### Added
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/completions/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function suggested(id: string, source: string): void {
}
}

export function accept(id: string, lines: number): void {
export function accept(id: string, lines: number, chars: number): void {
const completionEvent = displayedCompletions.get(id)
if (!completionEvent || completionEvent.acceptedAt) {
// Log a debug event, this case should not happen in production
Expand All @@ -140,6 +140,7 @@ export function accept(id: string, lines: number): void {
logCompletionEvent('accepted', {
...completionEvent.params,
lines,
chars,
otherCompletionProviderEnabled: otherCompletionProviderEnabled(),
})
}
Expand Down
14 changes: 11 additions & 3 deletions vscode/src/completions/vscodeInlineCompletionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,15 @@ export class InlineCompletionItemProvider implements vscode.InlineCompletionItem
}
}

public handleDidAcceptCompletionItem(logId: string, lines: number): void {
public handleDidAcceptCompletionItem(logId: string, completion: InlineCompletionItem): void {
// When a completion is accepted, the lastCandidate should be cleared. This makes sure the
// log id is never reused if the completion is accepted.
this.lastCandidate = undefined

CompletionLogger.accept(logId, lines)
const lines = completion.insertText.split(/\r\n|\r|\n/).length
const chars = completion.insertText.length

CompletionLogger.accept(logId, lines, chars)
}

/**
Expand Down Expand Up @@ -244,7 +247,12 @@ export class InlineCompletionItemProvider implements vscode.InlineCompletionItem
{
title: 'Completion accepted',
command: 'cody.autocomplete.inline.accepted',
arguments: [{ codyLogId: logId, codyLines: completion.insertText.split(/\r\n|\r|\n/).length }],
arguments: [
{
codyLogId: logId,
codyCompletion: completion,
},
],
}
)
})
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ function createCompletionsProvider(
})

disposables.push(
vscode.commands.registerCommand('cody.autocomplete.inline.accepted', ({ codyLogId, codyLines }) => {
completionsProvider.handleDidAcceptCompletionItem(codyLogId, codyLines)
vscode.commands.registerCommand('cody.autocomplete.inline.accepted', ({ codyLogId, codyCompletion }) => {
completionsProvider.handleDidAcceptCompletionItem(codyLogId, codyCompletion)
}),
vscode.languages.registerInlineCompletionItemProvider('*', completionsProvider),
registerAutocompleteTraceView(completionsProvider)
Expand Down