Skip to content

Commit

Permalink
Merge branch 'main' into vb/autoedits-analytics-logger-integration-6
Browse files Browse the repository at this point in the history
  • Loading branch information
valerybugakov committed Jan 6, 2025
2 parents 15cead5 + 1f39390 commit 39790e0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
9 changes: 7 additions & 2 deletions vscode/src/autoedits/autoedits-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from 'vscode'
import {
type AutoEditsModelConfig,
type AutoEditsTokenLimit,
authStatus,
isDotComAuthed,
} from '@sourcegraph/cody-shared'

Expand Down Expand Up @@ -85,6 +86,10 @@ export function getAutoeditsProviderConfig(): AutoeditsProviderConfig {

/**
* A singleton for the static autoedits provider config.
* TODO: make it reactive to VS Code settings changes.
*/
export const autoeditsProviderConfig = getAutoeditsProviderConfig()
export let autoeditsProviderConfig = getAutoeditsProviderConfig()

// Recompute autoedits config on auth status change.
authStatus.subscribe(() => {
autoeditsProviderConfig = getAutoeditsProviderConfig()
})
16 changes: 8 additions & 8 deletions vscode/src/completions/context/context-mixer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ describe('ContextMixer', () => {
strategyFactory: createMockStrategy([]),
contextRankingStrategy: ContextRankingStrategy.Default,
})
const { context, logSummary } = await mixer.getContext(defaultOptions)
const { context, contextSummary } = await mixer.getContext(defaultOptions)

expect(normalize(context)).toEqual([])
expect(logSummary).toEqual({
expect(contextSummary).toEqual({
duration: 0,
retrieverStats: {},
strategy: 'none',
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('ContextMixer', () => {
]),
contextRankingStrategy: ContextRankingStrategy.Default,
})
const { context, logSummary } = await mixer.getContext(defaultOptions)
const { context, contextSummary } = await mixer.getContext(defaultOptions)
expect(normalize(context)).toEqual([
{
fileName: 'foo.ts',
Expand All @@ -134,7 +134,7 @@ describe('ContextMixer', () => {
type: 'file',
},
])
expect(logSummary).toEqual({
expect(contextSummary).toEqual({
duration: expect.any(Number),
retrieverStats: {
'jaccard-similarity': {
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('ContextMixer', () => {
]),
contextRankingStrategy: ContextRankingStrategy.Default,
})
const { context, logSummary } = await mixer.getContext(defaultOptions)
const { context, contextSummary } = await mixer.getContext(defaultOptions)

// The results have overlaps in `foo.ts` and `bar.ts`. `foo.ts` is ranked higher in both
// result sets, thus we expect the overlapping `foo.ts` ranges to appear first.
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('ContextMixer', () => {
},
]
`)
expect(logSummary).toEqual({
expect(contextSummary).toEqual({
duration: expect.any(Number),
retrieverStats: {
retriever1: {
Expand Down Expand Up @@ -422,7 +422,7 @@ describe('ContextMixer', () => {
]

setupTest(primaryRetrievers, loggingRetrievers)
const { context, logSummary, contextLoggingSnippets } =
const { context, contextSummary, contextLoggingSnippets } =
await mixer.getContext(defaultOptions)

expect(normalize(context)).toEqual([
Expand All @@ -441,7 +441,7 @@ describe('ContextMixer', () => {
endLine: 0,
},
])
expect(logSummary).toEqual({
expect(contextSummary).toEqual({
duration: expect.any(Number),
retrieverStats: {
retriever1: {
Expand Down
10 changes: 5 additions & 5 deletions vscode/src/completions/context/context-mixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ContextSummary {

export interface GetContextResult {
context: AutocompleteContextSnippet[]
logSummary: ContextSummary
contextSummary: ContextSummary
contextLoggingSnippets: AutocompleteContextSnippet[]
}

Expand Down Expand Up @@ -114,7 +114,7 @@ export class ContextMixer implements vscode.Disposable {
if (retrieversWithDataLogging.length === 0) {
return {
context: [],
logSummary: {
contextSummary: {
strategy: 'none',
totalChars: options.docContext.prefix.length + options.docContext.suffix.length,
prefixChars: options.docContext.prefix.length,
Expand Down Expand Up @@ -165,7 +165,7 @@ export class ContextMixer implements vscode.Disposable {
if (results.length === 0) {
return {
context: [],
logSummary: {
contextSummary: {
strategy: 'none',
totalChars: options.docContext.prefix.length + options.docContext.suffix.length,
prefixChars: options.docContext.prefix.length,
Expand Down Expand Up @@ -225,7 +225,7 @@ export class ContextMixer implements vscode.Disposable {
position++
}

const logSummary: ContextSummary = {
const contextSummary: ContextSummary = {
strategy,
duration: performance.now() - start,
totalChars,
Expand All @@ -236,7 +236,7 @@ export class ContextMixer implements vscode.Disposable {

return {
context: mixedContext,
logSummary,
contextSummary,
contextLoggingSnippets,
}
}
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/completions/get-inline-completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ async function doGetInlineCompletions(
],
})

CompletionAnalyticsLogger.networkRequestStarted(logId, contextResult?.logSummary)
CompletionAnalyticsLogger.networkRequestStarted(logId, contextResult?.contextSummary)
stageRecorder.record('preNetworkRequest')

// Get the processed completions from providers
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/completions/tracer/traceView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ${markdownList({ ...otherOptions, completionIntent: completionIntent || 'unknown
: `
## Context
${data.context ? markdownList(data.context.logSummary) : ''}
${data.context ? markdownList(data.context.contextSummary) : ''}
${
data.context === null || data.context.context.length === 0
Expand Down
8 changes: 8 additions & 0 deletions vscode/src/testutils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ const languages: Partial<typeof vscode_types.languages> = {
'vimrc',
])
},
getDiagnostics() {
return []
},
}

export enum TextDocumentChangeReason {
Expand Down Expand Up @@ -805,6 +808,9 @@ export const vsCodeMocks = {
},
onDidChangeActiveTextEditor() {},
onDidChangeTextEditorSelection() {},
onDidChangeTextEditorVisibleRanges() {},
onDidChangeNotebookEditorVisibleRanges() {},
onDidChangeActiveNotebookEditor() {},
onDidChangeWindowState() {},
state: { focused: false },
createTextEditorDecorationType: () => ({
Expand All @@ -826,6 +832,7 @@ export const vsCodeMocks = {
},
commands: {
registerCommand: () => ({ dispose: () => {} }),
executeCommand: () => Promise.resolve(),
},
workspace: {
fs: workspaceFs,
Expand All @@ -852,6 +859,7 @@ export const vsCodeMocks = {
return path.toString()
},
onDidChangeTextDocument() {},
onDidOpenTextDocument() {},
onDidCloseTextDocument() {},
onDidRenameFiles() {},
onDidDeleteFiles() {},
Expand Down

0 comments on commit 39790e0

Please sign in to comment.