diff --git a/vscode/src/autoedits/autoedits-config.ts b/vscode/src/autoedits/autoedits-config.ts index 5b9ed6842ce1..69dc6ed9a3a7 100644 --- a/vscode/src/autoedits/autoedits-config.ts +++ b/vscode/src/autoedits/autoedits-config.ts @@ -3,6 +3,7 @@ import * as vscode from 'vscode' import { type AutoEditsModelConfig, type AutoEditsTokenLimit, + authStatus, isDotComAuthed, } from '@sourcegraph/cody-shared' @@ -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() +}) diff --git a/vscode/src/completions/context/context-mixer.test.ts b/vscode/src/completions/context/context-mixer.test.ts index efea853009b3..d75e47d75ea4 100644 --- a/vscode/src/completions/context/context-mixer.test.ts +++ b/vscode/src/completions/context/context-mixer.test.ts @@ -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', @@ -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', @@ -134,7 +134,7 @@ describe('ContextMixer', () => { type: 'file', }, ]) - expect(logSummary).toEqual({ + expect(contextSummary).toEqual({ duration: expect.any(Number), retrieverStats: { 'jaccard-similarity': { @@ -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. @@ -256,7 +256,7 @@ describe('ContextMixer', () => { }, ] `) - expect(logSummary).toEqual({ + expect(contextSummary).toEqual({ duration: expect.any(Number), retrieverStats: { retriever1: { @@ -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([ @@ -441,7 +441,7 @@ describe('ContextMixer', () => { endLine: 0, }, ]) - expect(logSummary).toEqual({ + expect(contextSummary).toEqual({ duration: expect.any(Number), retrieverStats: { retriever1: { diff --git a/vscode/src/completions/context/context-mixer.ts b/vscode/src/completions/context/context-mixer.ts index 3f6a6dccad76..b5a341e063dd 100644 --- a/vscode/src/completions/context/context-mixer.ts +++ b/vscode/src/completions/context/context-mixer.ts @@ -64,7 +64,7 @@ export interface ContextSummary { export interface GetContextResult { context: AutocompleteContextSnippet[] - logSummary: ContextSummary + contextSummary: ContextSummary contextLoggingSnippets: AutocompleteContextSnippet[] } @@ -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, @@ -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, @@ -225,7 +225,7 @@ export class ContextMixer implements vscode.Disposable { position++ } - const logSummary: ContextSummary = { + const contextSummary: ContextSummary = { strategy, duration: performance.now() - start, totalChars, @@ -236,7 +236,7 @@ export class ContextMixer implements vscode.Disposable { return { context: mixedContext, - logSummary, + contextSummary, contextLoggingSnippets, } } diff --git a/vscode/src/completions/get-inline-completions.ts b/vscode/src/completions/get-inline-completions.ts index 69733c73dd58..989f84ebb4a6 100644 --- a/vscode/src/completions/get-inline-completions.ts +++ b/vscode/src/completions/get-inline-completions.ts @@ -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 diff --git a/vscode/src/completions/tracer/traceView.ts b/vscode/src/completions/tracer/traceView.ts index 08ee590f19a6..8e639fe62375 100644 --- a/vscode/src/completions/tracer/traceView.ts +++ b/vscode/src/completions/tracer/traceView.ts @@ -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 diff --git a/vscode/src/testutils/mocks.ts b/vscode/src/testutils/mocks.ts index d22b053a60c4..a649a9155ad1 100644 --- a/vscode/src/testutils/mocks.ts +++ b/vscode/src/testutils/mocks.ts @@ -740,6 +740,9 @@ const languages: Partial = { 'vimrc', ]) }, + getDiagnostics() { + return [] + }, } export enum TextDocumentChangeReason { @@ -805,6 +808,9 @@ export const vsCodeMocks = { }, onDidChangeActiveTextEditor() {}, onDidChangeTextEditorSelection() {}, + onDidChangeTextEditorVisibleRanges() {}, + onDidChangeNotebookEditorVisibleRanges() {}, + onDidChangeActiveNotebookEditor() {}, onDidChangeWindowState() {}, state: { focused: false }, createTextEditorDecorationType: () => ({ @@ -826,6 +832,7 @@ export const vsCodeMocks = { }, commands: { registerCommand: () => ({ dispose: () => {} }), + executeCommand: () => Promise.resolve(), }, workspace: { fs: workspaceFs, @@ -852,6 +859,7 @@ export const vsCodeMocks = { return path.toString() }, onDidChangeTextDocument() {}, + onDidOpenTextDocument() {}, onDidCloseTextDocument() {}, onDidRenameFiles() {}, onDidDeleteFiles() {},