Skip to content

Commit

Permalink
feat(auto-edits): clean auto-edits output channel (#6547)
Browse files Browse the repository at this point in the history
Clean the output logger for `auto-edits`:
1. Most of the debugging calls (to check where the `auto-edits` might
break are enabled only if verbose debugging true.
2. Large logs like `prompt` are shorted similar to autocomplete prompt
logs.
  • Loading branch information
hitesh-1997 authored Jan 8, 2025
1 parent 3360b83 commit ba5d332
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 50 deletions.
8 changes: 3 additions & 5 deletions vscode/src/autoedits/adapters/cody-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ export class CodyGatewayAdapter implements AutoeditsModelAdapter {
}
return response.choices[0].text
} catch (error) {
autoeditsOutputChannelLogger.logError(
'getModelResponse',
'Error calling Cody Gateway:',
error
)
autoeditsOutputChannelLogger.logError('getModelResponse', 'Error calling Cody Gateway:', {
verbose: error,
})
throw error
}
}
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/autoedits/adapters/create-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createAutoeditsModelAdapter({
? new SourcegraphChatAdapter(chatClient)
: new SourcegraphCompletionsAdapter()
default:
autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logError(
'createAutoeditsModelAdapter',
`Provider ${providerName} not supported`
)
Expand Down
8 changes: 3 additions & 5 deletions vscode/src/autoedits/adapters/fireworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ export class FireworksAdapter implements AutoeditsModelAdapter {
}
return response.choices[0].text
} catch (error) {
autoeditsOutputChannelLogger.logError(
'getModelResponse',
'Error calling Fireworks API:',
error
)
autoeditsOutputChannelLogger.logError('getModelResponse', 'Error calling Fireworks API:', {
verbose: error,
})
throw error
}
}
Expand Down
4 changes: 3 additions & 1 deletion vscode/src/autoedits/adapters/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export class OpenAIAdapter implements AutoeditsModelAdapter {
)
return response.choices[0].message.content
} catch (error) {
autoeditsOutputChannelLogger.logError('getModelResponse', 'Error calling OpenAI API:', error)
autoeditsOutputChannelLogger.logError('getModelResponse', 'Error calling OpenAI API:', {
verbose: error,
})
throw error
}
}
Expand Down
4 changes: 3 additions & 1 deletion vscode/src/autoedits/adapters/sourcegraph-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class SourcegraphChatAdapter implements AutoeditsModelAdapter {
autoeditsOutputChannelLogger.logError(
'getModelResponse',
'Error calling Sourcegraph Chat:',
error
{
verbose: error,
}
)
throw error
}
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/autoedits/adapters/sourcegraph-completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class SourcegraphCompletionsAdapter implements AutoeditsModelAdapter {
autoeditsOutputChannelLogger.logError(
'getModelResponse',
'Error calling Sourcegraph Completions:',
error
{ verbose: error }
)
throw error
}
Expand Down
39 changes: 27 additions & 12 deletions vscode/src/autoedits/autoedits-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v

await new Promise(resolve => setTimeout(resolve, INLINE_COMPLETION_DEFAULT_DEBOUNCE_INTERVAL_MS))
if (abortSignal.aborted) {
autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'debounce aborted before calculating getCurrentDocContext'
)
return null
}

autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'Calculating getCurrentDocContext...'
)
Expand All @@ -189,7 +189,7 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
tokenBudget: autoeditsProviderConfig.tokenLimit,
})

autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'Calculating context from contextMixer...'
)
Expand Down Expand Up @@ -220,14 +220,14 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
},
})
if (abortSignal.aborted) {
autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'aborted in getContext'
)
return null
}

autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'Calculating prompt from promptStrategy...'
)
Expand All @@ -239,7 +239,7 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
isChatModel: autoeditsProviderConfig.isChatModel,
})

autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'Calculating prediction from getPrediction...'
)
Expand All @@ -250,7 +250,7 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
codeToReplaceData,
})
if (abortSignal?.aborted || !initialPrediction) {
autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'aborted after getPrediction'
)
Expand Down Expand Up @@ -279,7 +279,10 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
})

if (prediction === codeToRewrite) {
autoeditsOutputChannelLogger.logDebug('skip', 'prediction equals to code to rewrite')
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'prediction equals to code to rewrite'
)
return null
}

Expand All @@ -290,7 +293,10 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
})

if (shouldFilterPredictionBasedRecentEdits) {
autoeditsOutputChannelLogger.logDebug('skip', 'based on recent edits')
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'based on recent edits'
)
return null
}

Expand All @@ -303,7 +309,10 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
suffix: codeToReplaceData.suffixInArea + codeToReplaceData.suffixAfterArea,
})
) {
autoeditsOutputChannelLogger.logDebug('skip', 'prediction equals to code to rewrite')
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'skip because the prediction equals to code to rewrite'
)
return null
}

Expand All @@ -319,13 +328,19 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
})

if (inlineCompletionItems === null && updatedDecorationInfo === null) {
autoeditsOutputChannelLogger.logDebug('skip', 'no suggestion to render')
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'no suggestion to render'
)
return null
}

const editor = vscode.window.activeTextEditor
if (!editor || !areSameUriDocs(document, editor.document)) {
autoeditsOutputChannelLogger.logDebug('skip', 'no active editor')
autoeditsOutputChannelLogger.logDebugIfVerbose(
'provideInlineCompletionItems',
'no active editor'
)
return null
}

Expand Down
3 changes: 1 addition & 2 deletions vscode/src/autoedits/filter-prediction-edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export class FilterPredictionBasedOnRecentEdits implements vscode.Disposable {
autoeditsOutputChannelLogger.logDebug(
'isTextDocumentChangeReverted',
'Filtered the prediction based on recent edits match',
'Diff calculated for filtering based on recent edits\n',
diff1
{ verbose: diff1 }
)
}
return true
Expand Down
22 changes: 21 additions & 1 deletion vscode/src/autoedits/output-channel-logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import * as vscode from 'vscode'
import { getConfiguration } from '../configuration'
import { Logger } from '../output-channel-logger'

export const autoeditsOutputChannelLogger = new Logger('AutoEdits')
export class AutoEditsOutputChannelLogger extends Logger {
private readonly logger: Logger

constructor(feature: string) {
super(feature)
this.logger = new Logger(feature)
}

logDebugIfVerbose(filterLabel: string, text: string, ...args: unknown[]): void {
const workspaceConfig = vscode.workspace.getConfiguration()
const { debugVerbose } = getConfiguration(workspaceConfig)

if (debugVerbose) {
this.logger.logDebug(filterLabel, text, ...args)
}
}
}

export const autoeditsOutputChannelLogger = new AutoEditsOutputChannelLogger('AutoEdits')
5 changes: 4 additions & 1 deletion vscode/src/autoedits/prompt/default-prompt-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type PromptString, ps } from '@sourcegraph/cody-shared'
import { RetrieverIdentifier } from '../../completions/context/utils'
import { autoeditsOutputChannelLogger } from '../output-channel-logger'

import { shortenPromptForOutputChannel } from '../../../src/completions/output-channel-logger'
import { AutoeditsUserPromptStrategy, type UserPromptArgs } from './base'
import * as constants from './constants'
import {
Expand Down Expand Up @@ -72,7 +73,9 @@ export class DefaultUserPromptStrategy extends AutoeditsUserPromptStrategy {
constants.FINAL_USER_PROMPT
)

autoeditsOutputChannelLogger.logDebug('getUserPrompt', 'Prompt\n', finalPrompt)
autoeditsOutputChannelLogger.logDebugIfVerbose('DefaultUserPromptStrategy', 'getUserPrompt', {
verbose: shortenPromptForOutputChannel(finalPrompt.toString(), []),
})
return finalPrompt
}
}
2 changes: 1 addition & 1 deletion vscode/src/autoedits/prompt/prompt-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export function getContextItemMappingWithTokenLimit(
if (tokenLimit !== undefined) {
contextItemMapping.set(identifier, getContextItemsInTokenBudget(items, tokenLimit))
} else {
autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logError(
'getContextItemMappingWithTokenLimit',
`No token limit for ${identifier}`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { groupConsecutiveItemsByPredicate } from '../../completions/context/retr
import { RetrieverIdentifier } from '../../completions/context/utils'
import { autoeditsOutputChannelLogger } from '../output-channel-logger'

import { shortenPromptForOutputChannel } from '../../../src/completions/output-channel-logger'
import { AutoeditsUserPromptStrategy, type UserPromptArgs } from './base'
import * as constants from './constants'
import {
Expand Down Expand Up @@ -71,7 +72,9 @@ export class ShortTermPromptStrategy extends AutoeditsUserPromptStrategy {
constants.FINAL_USER_PROMPT
)

autoeditsOutputChannelLogger.logDebug('getUserPrompt', 'Prompt\n', finalPrompt)
autoeditsOutputChannelLogger.logDebugIfVerbose('ShortTermPromptStrategy', 'getUserPrompt', {
verbose: shortenPromptForOutputChannel(finalPrompt.toString(), []),
})
return finalPrompt
}

Expand Down
5 changes: 3 additions & 2 deletions vscode/src/autoedits/renderer/inline-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from 'vscode'
import { isFileURI } from '@sourcegraph/cody-shared'

import { completionMatchesSuffix } from '../../completions/is-completion-visible'
import { shortenPromptForOutputChannel } from '../../completions/output-channel-logger'
import { getNewLineChar } from '../../completions/text-processing'
import { autoeditsOutputChannelLogger } from '../output-channel-logger'

Expand Down Expand Up @@ -86,10 +87,10 @@ export class AutoEditsInlineRendererManager
),
]

autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'tryMakeInlineCompletions',
'Autocomplete Inline Response: ',
completionText
{ verbose: shortenPromptForOutputChannel(completionText, []) }
)
}

Expand Down
4 changes: 2 additions & 2 deletions vscode/src/autoedits/renderer/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ export class AutoEditsDefaultRendererManager implements AutoEditsRendererManager
autoeditsOutputChannelLogger.logDebug(
'tryMakeInlineCompletions',
'Autocomplete Inline Response: ',
autocompleteResponse
{ verbose: autocompleteResponse }
)
return {
inlineCompletionItems: [inlineCompletionItem],
updatedDecorationInfo: null,
updatedPrediction,
}
}
autoeditsOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'tryMakeInlineCompletions',
'Rendering a diff view for auto-edits.'
)
Expand Down
8 changes: 4 additions & 4 deletions vscode/src/completions/context/context-mixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
dedupeWith,
wrapInActiveSpan,
} from '@sourcegraph/cody-shared'
import { autoeditsOutputChannelLogger } from '../../autoedits/output-channel-logger'
import type { LastInlineCompletionCandidate } from '../get-inline-completions'
import { autocompleteOutputChannelLogger } from '../output-channel-logger'
import type { ContextRetriever } from '../types'
import {
DefaultCompletionsContextRanker,
Expand Down Expand Up @@ -153,7 +153,7 @@ export class ContextMixer implements vscode.Disposable {

// Extract back the context results for the original retrievers
const results = this.extractOriginalRetrieverResults(resultsWithDataLogging, retrievers)
autocompleteOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'ContextMixer',
`Extracted ${results.length} contexts from the retrievers`
)
Expand All @@ -177,13 +177,13 @@ export class ContextMixer implements vscode.Disposable {
}
}

autocompleteOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'ContextMixer',
`Fusing ${results.length} context results with ${this.contextRankingStrategy}`
)
const contextRanker = new DefaultCompletionsContextRanker(this.contextRankingStrategy)
const fusedResults = contextRanker.rankAndFuseContext(results)
autocompleteOutputChannelLogger.logDebug('ContextMixer', 'Fused context results')
autoeditsOutputChannelLogger.logDebugIfVerbose('ContextMixer', 'Fused context results')

// The total chars size hint is inclusive of the prefix and suffix sizes, so we seed the
// total chars with the prefix and suffix sizes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AutocompleteContextSnippet } from '@sourcegraph/cody-shared'
import { isDefined } from '@sourcegraph/cody-shared'
import { XMLBuilder } from 'fast-xml-parser'
import * as vscode from 'vscode'
import { autocompleteOutputChannelLogger } from '../../../output-channel-logger'
import { autoeditsOutputChannelLogger } from '../../../../autoedits/output-channel-logger'
import type { ContextRetriever, ContextRetrieverOptions } from '../../../types'
import { RetrieverIdentifier } from '../../utils'
import { getCellIndexInActiveNotebookEditor, getNotebookCells } from './notebook-utils'
Expand Down Expand Up @@ -46,7 +46,7 @@ export class DiagnosticsRetriever implements vscode.Disposable, ContextRetriever
document,
position,
}: ContextRetrieverOptions): Promise<AutocompleteContextSnippet[]> {
autocompleteOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'diagnostics retriever',
'Retrieving diagnostics context'
)
Expand All @@ -56,7 +56,7 @@ export class DiagnosticsRetriever implements vscode.Disposable, ContextRetriever
? await this.getDiagnosticsForNotebook(position)
: await this.getDiagnosticsForDocument(document, position)

autocompleteOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'diagnostics retriever',
`Retrieved ${diagnosticsSnippets.length} diagnostics context`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type PromptString, contextFiltersProvider } from '@sourcegraph/cody-sha
import type { AutocompleteContextSnippet } from '@sourcegraph/cody-shared'
import type { AutocompleteContextSnippetMetadataFields } from '@sourcegraph/cody-shared'
import * as vscode from 'vscode'
import { autocompleteOutputChannelLogger } from '../../../output-channel-logger'
import { autoeditsOutputChannelLogger } from '../../../../autoedits/output-channel-logger'
import type { ContextRetriever, ContextRetrieverOptions } from '../../../types'
import { RetrieverIdentifier, type ShouldUseContextParams, shouldBeUsedAsContext } from '../../utils'
import type {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class RecentEditsRetriever implements vscode.Disposable, ContextRetriever
}

public async retrieve(options: ContextRetrieverOptions): Promise<AutocompleteContextSnippet[]> {
autocompleteOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'recent edits retrieve',
'Retrieving recent edits context'
)
Expand All @@ -73,7 +73,7 @@ export class RecentEditsRetriever implements vscode.Disposable, ContextRetriever
}
autocompleteContextSnippets.push(autocompleteSnippet)
}
autocompleteOutputChannelLogger.logDebug(
autoeditsOutputChannelLogger.logDebugIfVerbose(
'recent edits retrieve',
`Retrieved ${autocompleteContextSnippets.length} recent edits context`
)
Expand Down
Loading

0 comments on commit ba5d332

Please sign in to comment.