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

Fix missing current repo context in jetbrains #6649

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Changes from all 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
4 changes: 3 additions & 1 deletion vscode/src/chat/initialContext.ts
Original file line number Diff line number Diff line change
@@ -228,7 +228,9 @@ export function getCorpusContextItemsForEditorState(): Observable<
icon: 'folder',
})
}
} else {
}

if (items.length === 0) {
// TODO(sqs): Support multi-root. Right now, this only supports the 1st workspace root.
const workspaceFolder = vscode.workspace.workspaceFolders?.at(0)
if (workspaceFolder) {
7 changes: 0 additions & 7 deletions vscode/src/repository/remoteRepos.ts
Original file line number Diff line number Diff line change
@@ -50,13 +50,6 @@ export const remoteReposForAllWorkspaceFolders: Observable<
return Observable.of([])
}

// NOTE(sqs): This check is to preserve prior behavior where agent/JetBrains did not use
// the old WorkspaceReposMonitor. We should make it so they can use it. See
// https://linear.app/sourcegraph/issue/CODY-3906/agent-allow-use-of-existing-fallback-that-looks-at-gitconfig-to-get.
if (!vscodeGitAPI) {
return Observable.of([])
}

return combineLatest(
...workspaceFolders.map(folder => repoNameResolver.getRepoNamesContainingUri(folder.uri))
).pipe(
37 changes: 26 additions & 11 deletions vscode/test/e2e/chat-atFile.test.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import {
focusChatInputAtEnd,
getContextCell,
mentionMenu,
mentionMenuItems,
openContextCell,
openFileInEditorTab,
openMentionsForProvider,
@@ -31,7 +32,7 @@ test.extend<ExpectedV2Events>({
'cody.chat-question:executed',
'cody.chatResponse:noCode',
],
})('@-mention file in chat', async ({ page, sidebar }) => {
})('@-mention file in chat', async ({ page, sidebar, workspaceDirectory }) => {
// This test requires that the window be focused in the OS window manager because it deals with
// focus.
await page.bringToFront()
@@ -56,11 +57,10 @@ test.extend<ExpectedV2Events>({

// We should only match the relative visible path, not parts of the full path outside of the workspace.
// Eg. searching for "source" should not find all files if the project is inside `C:\Source`.
// TODO(dantup): After https://github.com/sourcegraph/cody/pull/2235 lands, add workspacedirectory to the test
// and assert that it contains `fixtures` to ensure this check isn't passing because the fixture folder no
// longer matches.
// Instead it should find Current Repository item.
await expect(workspaceDirectory).toContain('fixtures')
await chatInput.fill('@fixtures') // fixture is in the test project folder name, but not in the relative paths.
await expect(atMentionMenuMessage(chatPanelFrame, 'No files found')).toBeVisible()
await expect(mentionMenuItems(chatPanelFrame)).toHaveText([/^Current Repository/])

// Includes dotfiles after just "."
await chatInput.fill('@.')
@@ -326,8 +326,8 @@ test.extend<ExpectedV2Events>({
await chatInput.pressSequentially('fizzb', { delay: 10 })
await expect(chatPanelFrame.getByRole('option', { name: 'fizzbuzz()' })).toBeVisible()
await chatPanelFrame.getByRole('option', { name: 'fizzbuzz()' }).click()
await expect(chatInput).toHaveText('buzz.ts fizzbuzz() ')
await expect(chatInputMentions(chatInput)).toHaveText(['buzz.ts', 'fizzbuzz()'])
await expect(chatInput).toHaveText(/buzz.ts (workspace|sourcegraph.cody) fizzbuzz\(\) /)
await expect(chatInputMentions(chatInput)).toContainText(['buzz.ts', 'fizzbuzz()'])

// Submit the message
await chatInput.press('Enter')
@@ -358,12 +358,27 @@ test.extend<ExpectedV2Events>({
await selectLineRangeInEditorTab(page, 2, 5)

const [, lastChatInput] = await createEmptyChatPanel(page)
await expect(chatInputMentions(lastChatInput)).toHaveText(['buzz.ts', 'buzz.ts:2-5'], {
timeout: 2_000,
})
await expect(chatInputMentions(lastChatInput)).toHaveText(
[
'buzz.ts',
'buzz.ts:2-5',
// The repo context should appear in the chat, but depending
// on if you are running it locally or in CI, it may appear as
// sourcegraph/cody or workspace
/workspace|sourcegraph.cody/,
],
{
timeout: 3_000,
}
)

await lastChatInput.press('x')
await selectLineRangeInEditorTab(page, 7, 10)
await executeCommandInPalette(page, 'Cody: Add Selection to Cody Chat')
await expect(chatInputMentions(lastChatInput)).toHaveText(['buzz.ts', 'buzz.ts:2-5', 'buzz.ts:7-10'])
await expect(chatInputMentions(lastChatInput)).toHaveText([
'buzz.ts',
'buzz.ts:2-5',
/workspace|sourcegraph.cody/,
'buzz.ts:7-10',
])
})