Cody Quickstart
This quickstart guide shows how to use Cody in the VS Code editor. You'll learn about the following tasks:
- Chat with Cody to ask questions about your code
- Code completions and suggestions
- Use Cody to refactor code
- Use Cody to debug code and ask Cody to fix bugs
Prerequisites
Before you start, you'll need the following:
- Cody extension installed in your VS Code editor
- Free or Pro account via Sourcegraph.com or a Sourcegraph Enterprise account
- A project open in VS Code
Getting started with Cody
After installing the extension and connecting to a Sourcegraph instance, you can leverage Cody to use the best LLM and context to understand, write, and fix code. Click the Cody icon from the VS Code side activity bar to open the Cody chat panel.
By default, the chat input will have the context of your entire codebase, and Claude 3.5 Sonnet (New) is selected as the default chat model. Based on your Cody tier, you can change the LLM model and context based on your use case to optimize speed, accuracy, or cost.
To help you automate your key tasks in your development workflow, you get Prompts. If you are a part of an organization on Sourcegraph.com or a self-hosted Sourcegraph instance, you can view these pre-built Prompts created by your teammates. On the contrary, you can create your own Prompts via the Prompt Library from your Sourcegraph instance.
The Cody chat interface offers a few more options and settings. You can read more in these docs.
Chat with Cody
The best way to see Cody in action is through chat. Cody allows you to chat directly with AI to ask questions about your code. You can start by asking simple questions like:
- What does this code do?
- Explain this codebase in three to four lines
Or ask more complex questions like:
- Suggest ways to refactor the codebase?
- How can I make this code more performant?
Cody will respond with a code snippet, a suggested fix, or an explanation.
Code completions and suggestions
Cody helps you code faster by providing real-time single and multi-line code completions. It uses the context of the code around your cursor to make accurate suggestions and starts predicting what you're trying to write before you type it.
Let's try it by typing a bubbleSort()
function in a JavaScript file.
Cody automatically predicts the function body in gray-dimmed text. Press Tab
to accept the suggestion or Esc
to dismiss it.
Use Cody to refactor code
You can refactor your code with inline edits. All you need to do is highlight the code, hit the edit hotkey (Opt + K
), and describe a change. Cody will generate a diff for the change in seconds.
Let's use the same bubbleSort()
function from the previous section. Now, refactor the function to sort dates in descending order. Highlight the function and press Opt + K
.
Type your refactoring suggestion in the input field and press Enter
. Cody will generate a diff for the change in seconds. You can review the diff, accept the change, reject it, or retry if you are unsatisfied with the result.
Use Cody to debug code
You can ask Cody to debug your code and fix bugs. Cody chat and inline edits are both quite powerful in debugging. If there is a bug, you can ask Cody to debug and fix the code. VS Code and JetBrains IDEs offer Ask Cody to fix option.
When a mistake occurs, a red warning is triggered. Along with this, you get a lightbulb icon. If you click on this lightbulb icon, there is an Ask Cody to fix option. Click this, and Cody will try to fix the bug with a Cody is working notice.
That's it for this quickstart guide! Feel free to continue chatting with Cody to learn more about its capabilities.