Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 146208d

Browse files
Cody completions: Log multi-line completion requests and results (#52449)
Adds a flag to the event logs so we know how often multi-line suggestions are triggered. Logging how often they are accepted is a bit tricker and requires some resturcturing. For now we do not know for an accepted event wether it was a multi line or a single line completion. Will fix it up later (but I plan to cut a release in a bit) ## Test plan <img width="1092" alt="Screenshot 2023-05-25 at 14 14 15" src="https://github.com/sourcegraph/sourcegraph/assets/458591/da3ed4c4-b0c2-4906-9680-b6324c483c04"> <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles -->
1 parent 8292cab commit 146208d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

client/cody/src/completions/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { CompletionsDocumentProvider } from './docprovider'
1313
import { History } from './history'
1414
import { CompletionProvider, InlineCompletionProvider, ManualCompletionProvider } from './provider'
1515

16-
const LOG_INLINE = { type: 'inline' }
1716
const LOG_MANUAL = { type: 'manual' }
1817

1918
function lastNLines(text: string, n: number): string {
@@ -161,6 +160,8 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
161160
return []
162161
}
163162

163+
let multilineMode: null | 'block' = null
164+
164165
// TODO(philipp-spiess): Add a better detection for start-of-block and don't require C like
165166
// languages.
166167
const multilineEnabledLanguage =
@@ -173,6 +174,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
173174
prefix.trim().at(prefix.trim().length - 1) === '{'
174175
) {
175176
timeout = 500
177+
multilineMode = 'block'
176178
completers.push(
177179
new InlineCompletionProvider(
178180
this.completionsClient,
@@ -183,7 +185,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
183185
suffix,
184186
'',
185187
3,
186-
'block' // multiline
188+
multilineMode
187189
)
188190
)
189191
} else if (precedingLine.trim() === '') {
@@ -241,16 +243,21 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
241243
return []
242244
}
243245

244-
logEvent('CodyVSCodeExtension:completion:started', LOG_INLINE, LOG_INLINE)
246+
const logParams = {
247+
type: 'inline',
248+
multilineMode,
249+
}
250+
251+
logEvent('CodyVSCodeExtension:completion:started', logParams, logParams)
245252
const start = Date.now()
246253

247254
const results = rankCompletions(
248255
(await Promise.all(completers.map(c => c.generateCompletions(abortController.signal)))).flat()
249256
)
250257

251258
if (hasVisibleCompletions(results)) {
252-
const params = { ...LOG_INLINE, latency: Date.now() - start, timeout }
253-
logEvent('CodyVSCodeExtension:completion:suggested', params, params)
259+
const logParamsWithTimings = { ...logParams, latency: Date.now() - start, timeout }
260+
logEvent('CodyVSCodeExtension:completion:suggested', logParamsWithTimings, logParamsWithTimings)
254261
inlineCompletionsCache.add(results)
255262
return results.map(toInlineCompletionItem)
256263
}

0 commit comments

Comments
 (0)