Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support at-mentions context on edits #3091

Merged
merged 8 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/ui/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
: messageAtIndex?.text
if (inputText) {
setFormInput(inputText)
if (messageAtIndex.contextFiles) {
useOldChatMessageContext(messageAtIndex.contextFiles)
}
}
// move focus back to chatbox
setInputFocus(true)
},
[messageBeingEdited, setFormInput, setMessageBeingEdited, transcript]
Expand Down Expand Up @@ -345,6 +349,15 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
return `@${displayPath(contextFile.uri)}${range}${symbolName}`
}

// Add old context files from the transcript to the map
const useOldChatMessageContext = (oldContextFiles: ContextFile[]) => {
const contextFilesMap = new Map<string, ContextFile>()
for (const file of oldContextFiles) {
contextFilesMap.set(getContextFileDisplayText(file), file)
}
setChatContextFiles(contextFilesMap)
}

/**
* Callback function called when a chat context file is selected from the context selector.
* This updates the chat input with the selected file context.
Expand Down Expand Up @@ -693,11 +706,7 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
} else {
setFormInput(newHistoryInput.inputText)
// chatContextFiles uses a map but history only stores a simple array.
const contextFilesMap = new Map<string, ContextFile>()
for (const file of newHistoryInput.inputContextFiles) {
contextFilesMap.set(getContextFileDisplayText(file), file)
}
setChatContextFiles(contextFilesMap)
useOldChatMessageContext(newHistoryInput.inputContextFiles)
}
}
}
Expand All @@ -718,6 +727,7 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
onChatContextSelected,
enableNewChatMode,
resetContextSelection,
useOldChatMessageContext,
]
)

Expand Down
42 changes: 17 additions & 25 deletions vscode/test/e2e/chat-edits.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test'

import { sidebarSignin } from './common'
import { test } from './helpers'
import { test, withPlatformSlashes } from './helpers'

const isPlatform = (platform: string) => process.platform === platform
const isMac = isPlatform('darwin')
Expand Down Expand Up @@ -104,34 +104,26 @@ test('editing follow-up messages in chat view', async ({ page, sidebar }) => {
await expect(cancelEditButton).not.toBeVisible()
await expect(chatInput).toBeEmpty()
await expect(chatFrame.getByText('Explain @Main.java')).toBeVisible()
await chatInput.press('Escape')

// Add a new at-file to an old messages
await chatInput.press(`${osKey}+k`)
await chatInput.type('and @vgo', { delay: 50 })
await chatInput.press('Tab')
await expect(chatInput).toHaveValue(
withPlatformSlashes('Explain @Main.java and @lib/batches/env/var.go ')
)
await chatInput.press('Enter')
// both main.java and var.go should be used
await expect(chatFrame.getByText(/Context: 2 files/)).toBeVisible()
await chatFrame.getByText(/Context: 2 files/).click()
await expect(chatFrame.getByRole('button', { name: 'Main.java' })).toBeVisible()
await expect(
chatFrame.getByRole('button', { name: withPlatformSlashes('lib/batches/env/var.go') })
).toBeVisible()

// Meta+/ also creates a new chat session
await chatInput.press(`${osKey}+/`)
await expect(chatFrame.getByText('The End')).not.toBeVisible()

// TODO (bee) - update after switching to the new keybinding for toggling "New Chat Mode"
await expect(startNewChatButton).not.toBeVisible()
// // "MetaKey(MacOS)/Control" + "Shift" to toggle "New Chat Mode" on and off
// // When it's on, the submit button will be replaced with "Start New Chat" button
// await expect(submitMessageButton).toBeVisible()
// await chatInput.press(`${osKey}+Shift`)
// await expect(submitMessageButton).not.toBeVisible()
// await expect(startNewChatButton).toBeVisible()
// await chatInput.press(`${osKey}+Shift`)
// await expect(startNewChatButton).not.toBeVisible()
// await chatInput.press(`${osKey}+Shift`)
// await expect(startNewChatButton).toBeVisible()

// // With "New Chat Mode" enabled, submit a new message to start a new chat
// // The new message should be "The End"
// // And the last message should not be visible anymore
// await chatInput.fill('The End')
// await chatInput.press('Enter')
// await expect(chatFrame.getByText('The End')).toBeVisible()
// await expect(chatFrame.getByText('Explain @Main.java')).not.toBeVisible()

// // Meta+/ also creates a new chat session
// await chatInput.press(`${osKey}+/`)
// await expect(chatFrame.getByText('The End')).not.toBeVisible()
})
Loading