Skip to content

Commit a1bbacb

Browse files
committed
fix open file behavior on accepted changes
1 parent 4235561 commit a1bbacb

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

packages/core/src/amazonq/commons/diff.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,3 @@ export function createAmazonQUri(path: string, tabId: string) {
3333
// TODO change the featureDevScheme to a more general amazon q scheme
3434
return vscode.Uri.from({ scheme: featureDevScheme, path, query: `tabID=${tabId}` })
3535
}
36-
37-
export async function openFile(path: string) {
38-
if (!(await fs.exists(path))) {
39-
return
40-
}
41-
const fileUri = vscode.Uri.file(path)
42-
await vscode.commands.executeCommand('vscode.diff', fileUri, fileUri)
43-
}

packages/core/src/amazonq/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ export { amazonQHelpUrl } from '../shared/constants'
2727
export { listCodeWhispererCommandsWalkthrough } from '../codewhisperer/ui/statusBarMenu'
2828
export { focusAmazonQPanel, focusAmazonQPanelKeybinding } from '../codewhispererChat/commands/registerCommands'
2929
export { TryChatCodeLensProvider, tryChatCodeLensCommand } from '../codewhispererChat/editor/codelens'
30-
export {
31-
createAmazonQUri,
32-
openDiff,
33-
openDeletedDiff,
34-
getOriginalFileUri,
35-
getFileDiffUris,
36-
openFile,
37-
} from './commons/diff'
30+
export { createAmazonQUri, openDiff, openDeletedDiff, getOriginalFileUri, getFileDiffUris } from './commons/diff'
3831
export { CodeReference } from '../codewhispererChat/view/connector/connector'
3932
export { AuthMessageDataMap, AuthFollowUpType } from './auth/model'
4033
export { extractAuthFollowUp } from './util/authUtils'

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { openUrl } from '../../../shared/utilities/vsCodeUtils'
4343
import { getPathsFromZipFilePath } from '../../util/files'
4444
import { examples, messageWithConversationId } from '../../userFacingText'
4545
import { getWorkspaceFoldersByPrefixes } from '../../../shared/utilities/workspaceUtils'
46-
import { openDeletedDiff, openDiff, openFile } from '../../../amazonq/commons/diff'
46+
import { openDeletedDiff, openDiff } from '../../../amazonq/commons/diff'
4747
import { i18n } from '../../../shared/i18n-helper'
4848
import globals from '../../../shared/extensionGlobals'
4949
import { randomUUID } from '../../../shared'
@@ -750,7 +750,7 @@ export class FeatureDevController {
750750
this.sendAcceptCodeTelemetry(session, 1)
751751
await session.insertNewFiles([session.state.filePaths[filePathIndex]])
752752
await session.insertCodeReferenceLogs(session.state.references ?? [])
753-
await this.openFile(session.state.filePaths[filePathIndex])
753+
await this.openFile(session.state.filePaths[filePathIndex], tabId)
754754
} else {
755755
session.state.filePaths[filePathIndex].rejected = !session.state.filePaths[filePathIndex].rejected
756756
}
@@ -828,9 +828,10 @@ export class FeatureDevController {
828828
}
829829
}
830830

831-
private async openFile(filePath: NewFileInfo) {
832-
const absolutePath = path.join(filePath.workspaceFolder.uri.fsPath, filePath.relativePath)
833-
await openFile(absolutePath)
831+
private async openFile(filePath: NewFileInfo, tabId: string) {
832+
const leftPath = path.join(filePath.workspaceFolder.uri.fsPath, filePath.relativePath)
833+
const rightPath = filePath.virtualMemoryUri.path
834+
await openDiff(leftPath, rightPath, tabId)
834835
}
835836

836837
private async stopResponse(message: any) {

packages/core/src/test/amazonq/common/diff.test.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ import assert from 'assert'
1212
import * as path from 'path'
1313
import * as vscode from 'vscode'
1414
import sinon from 'sinon'
15-
import {
16-
createAmazonQUri,
17-
getFileDiffUris,
18-
getOriginalFileUri,
19-
openDeletedDiff,
20-
openDiff,
21-
openFile,
22-
} from '../../../amazonq'
15+
import { createAmazonQUri, getFileDiffUris, getOriginalFileUri, openDeletedDiff, openDiff } from '../../../amazonq'
2316
import { FileSystem } from '../../../shared/fs/fs'
2417

2518
describe('diff', () => {
@@ -119,21 +112,4 @@ describe('diff', () => {
119112
assert.deepStrictEqual(right, rightExpected)
120113
})
121114
})
122-
123-
describe('openFile', () => {
124-
it('file exists locally', async () => {
125-
sandbox.stub(FileSystem.prototype, 'exists').resolves(true)
126-
await openFile(filePath)
127-
128-
const expected = vscode.Uri.file(filePath)
129-
assert.ok(executeCommandSpy.calledWith('vscode.diff', expected, expected))
130-
})
131-
132-
it('file does not exists locally', async () => {
133-
sandbox.stub(FileSystem.prototype, 'exists').resolves(false)
134-
await openFile(filePath)
135-
136-
assert.ok(executeCommandSpy.notCalled)
137-
})
138-
})
139115
})

0 commit comments

Comments
 (0)