Install Cody for JetBrains

Learn how to use Cody and its features with the JetBrains IntelliJ editor.

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

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

cody-for-intellij

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.

cody-for-intellij-login

Context Selection

Cody automatically understands your codebase context based on the project opened in your workspace. However, at any point, you can override the automatic codebase detection by clicking on the repo name below the Cody chat and then adding the Git URL. This will allow Cody to start using the codebase context you’ve selected.

For Sourcegraph Enterprise users

To connect the extension with your Enterprise instance,

  • Log in to your Sourcegraph instance
  • Go to Settings > Access tokens (https://<your-instance>.sourcegraph.com/users/<your-username>/settings/tokens)
  • From here, click Generate new token
  • Next, go back to Cody Settings... in the IntelliJ editor
  • Click the plus icon (+) under Authentication and then select Log In with Token to Sourcegraph Enterprise
  • Finally, paste your newly created access token and instance URL in the respective fields and click Add Account to complete the process

For Sourcegraph.com users

Alternatively, you can click Log In to Sourcegraph to authenticate the IntelliJ extension with your Sourcegraph.com account.

Verifying the installation

Once Cody is connected successfully to your Sourcegraph instance, click the Cody icon from the sidebar again, and a panel will open. To verify that the Cody extension has been successfully installed and is working as expected, let's create an autocomplete suggestion.

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 Docstring
  • Generate Unit Test
  • Improve Variable Names
  • Smell Code

Let's understand how the Generate Docstring command generates code documentation for the sorting function.

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.

More resources

For more information on what to do next, we recommend the following resources: