Skip to content

Commit

Permalink
fix the diff for recent edits by replacing psDedent with ps (#5574)
Browse files Browse the repository at this point in the history
## Context
`psDedent` removed the spaces making diff invalid. Replaced with `ps`

## Test plan
1. Manual testing by checking the diff validity
  • Loading branch information
hitesh-1997 committed Sep 13, 2024
1 parent aabb842 commit 29b3a60
Showing 1 changed file with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { PromptString, contextFiltersProvider } from '@sourcegraph/cody-shared'
import { ps, psDedent } from '@sourcegraph/cody-shared'
import type { AutocompleteContextSnippet } from '@sourcegraph/cody-shared'
import * as vscode from 'vscode'
import { getLanguageConfig } from '../../../../tree-sitter/language'
import type { ContextRetriever, ContextRetrieverOptions } from '../../../types'
import { RetrieverIdentifier, type ShouldUseContextParams, shouldBeUsedAsContext } from '../../utils'

Expand Down Expand Up @@ -47,11 +45,7 @@ export class RecentEditsRetriever implements vscode.Disposable, ContextRetriever

const autocompleteContextSnippets = []
for (const diff of diffs) {
const content = this.getCommentedPromptForCompletions(
diff.languageId,
diff.uri,
diff.diff
).toString()
const content = diff.diff.toString()
const autocompleteSnippet = {
uri: diff.uri,
identifier: RetrieverIdentifier.RecentEditsRetriever,
Expand Down Expand Up @@ -89,18 +83,6 @@ export class RecentEditsRetriever implements vscode.Disposable, ContextRetriever
return diffs
}

public getCommentedPromptForCompletions(
languageId: string,
filename: vscode.Uri,
diff: PromptString
): PromptString {
const filePath = PromptString.fromDisplayPath(filename)
const languageConfig = getLanguageConfig(languageId)
const commentStart = languageConfig ? languageConfig.commentStart : ps`// `
const prompt = psDedent`${commentStart} Here is git diff of the recent change made to the file ${filePath} which is used to provide context for the completion:\n${diff}`
return prompt
}

public filterCandidateDiffs(
allDiffs: DiffAcrossDocuments[],
document: vscode.TextDocument
Expand Down

0 comments on commit 29b3a60

Please sign in to comment.