sourcegraph / cody

Type less, code more: Cody is an AI code assistant that uses advanced search and codebase context to help you write and fix code.
https://cody.dev
Apache License 2.0
2.53k stars 261 forks source link

Fall back to symf when remote indexed context is not available #5108

Closed beyang closed 1 month ago

beyang commented 1 month ago

Implements part of https://linear.app/sourcegraph/issue/AI-160/unify-context-fetching-code-paths

This change rolls in nearly all existing local PLG context into the ContextRetriever class, which will be the new focal point for retrieving unified context from both client and server. The new context retrieval is enabled with the cody.internal.serverSideContext flag.

The context incorporated in this change includes:

The context that has not been incorporated by this change:

The new context construction code path and the legacy context have been factored cleanly into legacyComputeContext and _computeContext methods within ChatController to make it clear what the delineation is.

Following this change, we should be able to remove the legacyComputeContext path altogether (but we should do more testing here). After that, the final step to unifying context fetching is to roll in the enterprise context fetching into ContextRetriever.

Here is a video showing how to enable the new context fetching path, along with how to compare context fetched from different sources in the UI:

https://github.com/user-attachments/assets/5cfa9468-9fa7-4ccb-8bf8-5ea3ebc5459e

As you can see from the video, there are some behavior changes and regressions in the new context fetching, which I'll look into following this PR. This PR does not change any production behavior because everything is gated behind the cody.internal.serverSideContext flag.

Test plan

github-actions[bot] commented 1 month ago

‼️ Hey @sourcegraph/cody-security, please review this PR carefully as it introduces the usage of an unsafe_ function or abuses PromptString.