Chat
Use Cody's chat to get contextually-aware answers to your questions.
Cody chat allows you to ask coding-related questions about any part of your codebase or specific code snippets. You can do it from the Chat panel of the supported editor extensions (VS Code, JetBrains) or in the web app.
Key functionalities in the VS Code extension include support for multiple simultaneous chats, enhanced chat context configurability through @-mentions, detailed visibility into the code that Cody read before providing a response, and more.
You can learn more about the IDE support for these functionalities in the feature parity reference.
Prerequisites
To use Cody's chat, you'll need to have the following:
- A Free or Pro account via Sourcegraph.com or a Sourcegraph Enterprise account
- A supported editor extension (VS Code, JetBrains) installed
How does chat work?
Cody answers questions by searching your codebase and retrieving context relevant to your questions. Cody uses several methods to search for context, including Sourcegraph's native search and keyword search. Finding and using context allows Cody to make informed responses based on your code rather than being limited to general knowledge. When Cody retrieves context to answer a question, it will tell you which code files it read to generate its response.
Cody can assist you with various use cases such as:
- Generating an API call: Cody can analyze your API schema to provide context for the code it generates
- Locating a specific component in your codebase: Cody can identify and describe the files where a particular component is defined
- Handling questions that involve multiple files, like understanding data population in a React app: Cody can locate React component definitions, helping you understand how data is passed and where it originates
Ask Cody your first question
Let's use Cody VS Code extension's chat interface to answer your first question.
- Click the Cody icon in the sidebar to view the detailed panel
- Next, click the icon for New Chat to open a new chat window
- Write your question or instruction to Cody and then press Enter.
For example, ask Cody "What does this file do?"
Cody will take a few seconds to process your question, providing contextual information about the files it reads and generating the answer.
Ask Cody to write code
The chat feature can also write code for your questions. For example, in VS Code, ask Cody to "write a function that sorts an array in ascending order".
You are provided with code suggestions in the chat window along with the following options for using the code.
- The Copy Code icon to your clipboard and paste the code suggestion into your code editor
- Insert the code suggestion at the current cursor location by the Insert Code at Cursor icon
- The Save Code to New File icon to save the code suggestion to a new file in your project
During the chat, if Cody needs additional context, it can ask you to provide more information with a follow-up question. If your question is beyond the scope of the context, Cody will ask you to provide an alternate question aligned with the context of your codebase.
Selecting Context
Cody's chat allows you to add files and symbols as context in your messages.
- Type
@
and then a filename to include a file as context - Type
@#
and then a symbol name to include the symbol's definition as context. Functions, methods, classes, types, etc., are all symbols
Cody's experimental OpenCtx support adds even more context sources, including Jira, Linear, Google Docs, Notion, and more.
Chat vs Commands
There could be scenarios when Cody's chat might not be able to answer your question. Or the answer lacks the context that you need. In these cases, it's recommended to use Cody commands. Cody's responses to commands might be better at times than responses to chats since they've been pre-packaged and prompt-engineered.