diff --git a/vscode/CHANGELOG.md b/vscode/CHANGELOG.md index 8658230d2f08..22fd6eccd9cf 100644 --- a/vscode/CHANGELOG.md +++ b/vscode/CHANGELOG.md @@ -8,6 +8,8 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a ### Fixed +Chat: Fix an issue in repository name resolution for workspaces that caused Chat to hang. [pull/5808](https://github.com/sourcegraph/cody/pull/5808) + ### Changed ## 1.36.2 diff --git a/vscode/src/repository/remoteRepos.ts b/vscode/src/repository/remoteRepos.ts index b75c0953b4aa..9c5c64f477be 100644 --- a/vscode/src/repository/remoteRepos.ts +++ b/vscode/src/repository/remoteRepos.ts @@ -6,7 +6,7 @@ import { fromVSCodeEvent, graphqlClient, isError, - pendingOperation, + type pendingOperation, startWith, switchMapReplayOperation, } from '@sourcegraph/cody-shared' @@ -61,22 +61,27 @@ export const remoteReposForAllWorkspaceFolders: Observable< ...workspaceFolders.map(folder => repoNameResolver.getRepoNamesContainingUri(folder.uri)) ).pipe( map(repoNamesLists => { - const repoNames = repoNamesLists.flat() - if (repoNames.includes(pendingOperation)) { - return pendingOperation - } - return repoNames as Exclude<(typeof repoNames)[number], typeof pendingOperation>[] + // Filter out non-array results (errors or pendingOperations) + // Flatten the array of arrays and ensure all elements are strings + const completedResults = repoNamesLists + .filter((names): names is string[] => Array.isArray(names)) + .flat() + .filter((name): name is string => typeof name === 'string') + + // Return completed results if available, otherwise an empty array + // This prevents hanging on pendingOperations for caught errors that returns an empty array/value + // that would be treated as a pendingOperation. + return completedResults.length > 0 ? completedResults : [] }), abortableOperation(async (repoNames, signal) => { - if (repoNames === pendingOperation) { - return pendingOperation - } if (repoNames.length === 0) { // If we pass an empty repoNames array to getRepoIds, we would // fetch the first 10 repos from the Sourcegraph instance, // because it would think that argument is not set. return [] } + // Process the validated results without checking for pendingOperation that + // would cause the abortableOperation to hang indefinitely. const reposOrError = await graphqlClient.getRepoIds( repoNames, MAX_REPO_COUNT,