Install Cody for JetBrains
Learn how to use Cody and its features with the JetBrains IntelliJ editor.
Cody support for the JetBrains editor extension is in the Beta stage.
The Cody extension by Sourcegraph enhances your coding experience in your IDE by providing intelligent code suggestions, context-aware completions, and advanced code analysis. This guide will walk you through the steps to install and set up Cody within your JetBrains environment.
Prerequisites
- You have the latest version of JetBrains IDEs installed
- You have a Free or Pro account via Sourcegraph.com or a Sourcegraph Enterprise account
- Cody is compatible with the following JetBrains IDEs:
Install the JetBrains IntelliJ Cody extension
Follow these steps to install the Cody plugin:
- Open JetBrains IntelliJ editor on your local machine
- Open Settings (Mac:
⌘+,
Windows:Ctrl+Alt+S
) and select Plugins - Type and search Sourcegraph Cody + Code Search extension and click Install
Alternatively, you can Download and install the extension from the Jetbrains marketplace.
Connect the extension to Sourcegraph
After a successful installation, Cody's icon appears in the sidebar. Clicking it prompts you to start with codehosts like GitHub, GitLab, and your Google login. This allows Cody to access your Sourcegraph.com account.
Alternatively, you can also click the Sign in with an Enterprise Instance to connect to your enterprise instance.
For Sourcegraph Enterprise users
To connect the extension with your Enterprise instance,
- Click Sign in with an Enterprise Instance
- Enter the server for your enterprise instance (e.g.
https://<your-instance>.sourcegraph.com
) - Select Generate new token. You'll be directed to the Access tokens page on your instance in the browser
- Generate a new token, copy it, and paste it into the Token field in your editor
- Click Sign in
For Sourcegraph.com users
For Cody Free and Cody Pro users, you can Log in through SSO to authenticate the IntelliJ extension with your Sourcegraph.com account.
Verifying the installation
Once Cody is successfully connected, you'll see that the sign-in panel has been replaced by a welcome message from Cody. Let's create an autocomplete suggestion to verify that the Cody extension has been successfully installed and is working as expected.
Cody provides intelligent code suggestions and context-aware autocompletions for numerous programming languages like JavaScript, Python, TypeScript, Go, etc.
- Create a new file in IntelliJ, for example,
code.js
- Next, type the following algorithm function to sort an array of numbers
function bubbleSort(array)
- As you start typing, Cody will automatically provide suggestions and context-aware completions based on your coding patterns and the code context
- These autocomplete suggestions appear as grayed text. To accept the suggestion, press the
Tab
key
Autocomplete
Autocomplete suggestions appear as inlay suggestions and are enabled by default in your JetBrains IntelliJ editor. With this setting, there is a list of programming languages supported and enabled by default.
To manually configure the Autocomplete feature,
- Go to the Cody Settings... from the Cody icon in the sidebar
- Next, click the Sourcegraph & Cody dropdown and select Cody
- The Autocomplete settings will appear with the list of Enabled Languages
In addition, Autocomplete suggestions use the same color as inline parameter hints according to your configured editor theme. However, you can optionally enable the Custom color for completions checkbox to customize the color of your choice.
Commands
Cody with JetBrains offers quick, ready-to-use Commands for common actions to write, describe, fix, and smell code. These allow you to run predefined actions with smart context-fetching anywhere in the editor, like:
- Explain Selected Code
- Generate Unit Test
- Smell Code
Supported LLM models
Cody offers a native support for Claude 2.0 for Chat, Commands, and Autocomplete on the Free tier. Users on Cody Pro have the ability to choose from a list of supported LLM models for Chat, Commands, and Autocomplete. These LLMs are Claude Instant, Claude 2.0, Claude 2.1, Claude 3 (Opus and Sonnet), ChatGPT 3.5 Turbo, ChatGPT 4 Turbo Preview, and Mixtral.
Cody Enterprise users get additional capabilities like BYOLLM (Bring Your Own LLM) key. Your site administrator determines the LLM, and cannot be changed within the editor. However, Cody Enterprise users when using Cody Gateway have the ability to configure custom models Anthropic (like Claude 2.0 and Claude Instant) and OpenAI (GPT 3.5 and GPT 4).
Chat history
Next to the chat tab, there is a chat history tab that displays all the previous chat interactions with Cody. You can revisit any of the previous chat interactions to get the context of the conversation.
Context fetching mechanism
JetBrains users on the Free or Pro plan can leverage local search as the primary context source for Cody chat. Local or remote embeddings will no longer be produced or used as a context source.
Enterprise users can leverage the full power of the Sourcegraph search engine as the primary context provider to Cody.
Context scope
JetBrains users on the Free or Pro plan get single-repo support in chat and can use one repo for context fetching. Enterprise users get multi-repo support in chat and can explicitly specify up to 10 additional repos they would like Cody to use for context.
Context Selection
Cody automatically understands your codebase context based on the project opened in your workspace. However, you can override the automatic codebase detection at any point by enabling the Chat Context checkbox. This provides enhanced context selection powered by local search and allows Cody to use the selected codebase to answer your questions.
Moreover, Cody's chat allows you to add files as context in your messages. Type @-file
in the Cody chat window and then a filename to include a file as context.
Updating the extension
JetBrains IntelliJ will typically notify you when updates are available for installed extensions. Follow the prompts to update the Cody extension to the latest version.