Skip to content

Commit

Permalink
Edit: Track events per diagnostic (#3692)
Browse files Browse the repository at this point in the history
  • Loading branch information
umpox authored Apr 5, 2024
1 parent b854832 commit b898b0e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
6 changes: 2 additions & 4 deletions vscode/src/edit/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode'

import type { ChatEventSource, ContextItem, ContextMessage, EditModel } from '@sourcegraph/cody-shared'

import type { FixupTask } from '../non-stop/FixupTask'
import type { FixupTask, FixupTelemetryMetadata } from '../non-stop/FixupTask'
import type { EditIntent, EditMode } from './types'

export interface ExecuteEditArguments {
Expand All @@ -20,9 +20,7 @@ export interface ExecuteEditArguments {
insertionPoint?: vscode.Position
}
source?: ChatEventSource
telemetryMetadata?: {
[key: string]: unknown
}
telemetryMetadata?: FixupTelemetryMetadata
}

/**
Expand Down
6 changes: 4 additions & 2 deletions vscode/src/edit/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export class EditManager implements vscode.Disposable {
model,
source,
configuration.destinationFile,
configuration.insertionPoint
configuration.insertionPoint,
telemetryMetadata
)
} else {
task = await this.controller.promptUserForTask(
Expand All @@ -132,7 +133,8 @@ export class EditManager implements vscode.Disposable {
mode,
model,
intent,
source
source,
telemetryMetadata
)
}

Expand Down
19 changes: 14 additions & 5 deletions vscode/src/non-stop/FixupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { FixupDocumentEditObserver } from './FixupDocumentEditObserver'
import type { FixupFile } from './FixupFile'
import { FixupFileObserver } from './FixupFileObserver'
import { FixupScheduler } from './FixupScheduler'
import { FixupTask, type FixupTaskID } from './FixupTask'
import { FixupTask, type FixupTaskID, type FixupTelemetryMetadata } from './FixupTask'
import { type Diff, computeDiff } from './diff'
import type { FixupActor, FixupFileCollection, FixupIdleTaskRunner, FixupTextChanged } from './roles'
import { CodyTaskState, getMinimumDistanceToRangeBoundary } from './utils'
Expand Down Expand Up @@ -154,6 +154,7 @@ export class FixupController
mode: task.mode,
source: task.source,
...countCode(replacementText),
...task.telemetryMetadata,
}
const { metadata, privateMetadata } = splitSafeMetadata(legacyMetadata)
if (!editOk) {
Expand Down Expand Up @@ -270,7 +271,8 @@ export class FixupController
mode: EditMode,
model: EditModel,
intent: EditIntent,
source: ChatEventSource
source: ChatEventSource,
telemetryMetadata?: FixupTelemetryMetadata
): Promise<FixupTask | null> {
const input = await getInput(
document,
Expand All @@ -295,7 +297,10 @@ export class FixupController
input.intent,
mode,
input.model,
source
source,
undefined,
undefined,
telemetryMetadata
)

// Return focus to the editor
Expand All @@ -314,7 +319,8 @@ export class FixupController
model: EditModel,
source?: ChatEventSource,
destinationFile?: vscode.Uri,
insertionPoint?: vscode.Position
insertionPoint?: vscode.Position,
telemetryMetadata?: FixupTelemetryMetadata
): Promise<FixupTask> {
const fixupFile = this.files.forUri(document.uri)
const task = new FixupTask(
Expand All @@ -327,7 +333,8 @@ export class FixupController
model,
source,
destinationFile,
insertionPoint
insertionPoint,
telemetryMetadata
)
this.tasks.set(task.id, task)
return task
Expand Down Expand Up @@ -414,6 +421,7 @@ export class FixupController
mode: task.mode,
source: task.source,
...countCode(task.replacement || ''),
...task.telemetryMetadata,
}
const { metadata, privateMetadata } = splitSafeMetadata(legacyMetadata)
if (!editOk) {
Expand Down Expand Up @@ -478,6 +486,7 @@ export class FixupController
model: task.model,
mode: task.mode,
intent: task.intent,
...task.telemetryMetadata,
},
})
}
Expand Down
10 changes: 9 additions & 1 deletion vscode/src/non-stop/FixupTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import { CodyTaskState } from './utils'

export type FixupTaskID = string

/**
* Arbitrary metadata that will be included in telemetry events for this task.
*/
export type FixupTelemetryMetadata = {
[key: string]: unknown
}

export class FixupTask {
public id: FixupTaskID
public state_: CodyTaskState = CodyTaskState.idle
Expand Down Expand Up @@ -65,7 +72,8 @@ export class FixupTask {
public source?: ChatEventSource,
/* The file to write the edit to. If not provided, the edit will be applied to the fixupFile. */
public destinationFile?: vscode.Uri,
public insertionPoint?: vscode.Position
public insertionPoint?: vscode.Position,
public readonly telemetryMetadata: FixupTelemetryMetadata = {}
) {
this.id = Date.now().toString(36).replaceAll(/\d+/g, '')
this.instruction = instruction.replace(/^\/(edit|fix)/, '').trim()
Expand Down

0 comments on commit b898b0e

Please sign in to comment.