Installing Cody for JetBrains
Learn how to use Cody and its features with JetBrains editors.
The Cody plugin 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 Cody plugin
Follow these steps to install the Cody plugin:
- Open a supported JetBrains editor on your local machine
- Open Settings (macOS:
⌘+,
Windows:Ctrl+Alt+S
) and select Plugins - Search for Cody: AI Coding Assistant with Autocomplete & Chat in the marketplace and click Install
Alternatively, you can also download and install the plugin from the JetBrains marketplace directly.
Connect the plugin to Sourcegraph
After a successful installation, the Cody icon appears in the Tool Windows Bar.
Cody Free or Cody Pro Users
Cody Free and Pro users can sign in to their Sourcegraph.com accounts using SSO through GitHub, GitLab, or Google.
Sourcegraph Enterprise Cody Users
Sourcegraph Enterprise users should connect Cody to their Enterprise instance by clicking Sign in with an Enterprise Instance.
To connect the plugin with your Enterprise instance,
- Click Sign in with an Enterprise Instance
- Enter the URL of your Enterprise instance. If you are unsure, please get in touch with your administrator
- Select Authorize in Browser. You'll be directed to an authorization page on your instance in the browser
Alternatively, you can access advanced authorization settings by clicking Show Advanced. You can manually enter a token generated from your User Settings in your Sourcegraph Enterprise instance or add optional custom request headers.
Verifying the installation
Once connected, click the Cody icon from the sidebar again. The Cody plugin will open in a configurable side panel.
Let's create an autocomplete suggestion to verify that the Cody plugin has been installed and works as expected.
Cody provides intelligent code suggestions and context-aware autocompletion for numerous programming languages, such as JavaScript, Python, TypeScript, Go, etc.
- Create a new file in your JetBrains IDE, for example,
code.js
- Next, type the following algorithm function to sort an array of numbers
JSfunction 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
Chat
Cody chat in JetBrains is available in a unified interface that opens right next to your code. Once connected to Sourcegraph, a new chat input field opens with the default @-mention
context chips.
All your previous and existing chats are stored for later use and can be accessed via the History icon from the top menu. You can download them to share or use later in a .json
file or delete them.
Chat interface
The chat interface is designed intuitively. Your very first chat input lives at the top of the panel, and the first message in any chat log will stay pinned to the top of the chat. After your first message, the chat input window moves to the bottom of the sidebar.
Since your first message to Cody anchors the conversation, you can return to the top chat box anytime, edit your prompt, or rerun it using a different LLM model.
Chat History
A chat history icon at the top of your chat input window allows you to navigate between chats (and search chats) without opening the Cody sidebar.
Changing LLM model for chat
For Chat:
- Open chat or toggle between editor and chat
- Click on the model selector (which by default indicates Claude 3.5 Sonnet)
- See the selection of models and click the model you desire. This model will now be the default model for any new chats
For Edit:
- On any file, select some code and right-click
- Select Cody > Edit Code (optionally, you can do this with
Opt+K
/Alt+K
) - Select the default model available
- See the selection of models and click the model you desire. This model will now be the default model for any new edits
Selecting Context with @-mentions
Cody's chat allows you to add files as context in your messages.
- Type
@-file
and then a filename to include a file as a context.
The @-file
also supports line numbers to query the context of large files. You can add ranges of large files to your context by @-mentioning a large file and appending a number range to the filename, for example, @filepath/filename:1-10
.
When you @-mention
files to add to Cody’s context window, the file lookup takes files.exclude
, search.exclude
, and .gitgnore
files into account. This makes the file search faster as a result up to 100ms.
Moreover, when you @-mention
files, Cody will track the number of characters in those files against the context window limit of the selected chat model. As you @-mention
multiple files, Cody will calculate how many tokens of the context window remain. When the remaining context window size becomes too small, you'll receive File too large errors when attempting to @-mention
additional files.
You can read more about context limits when selecting context here.
Context retrieval
When you start a new Cody chat, the input window opens with default @-mention
context chips for all the context it intends to use. This context is based on your current repository and current file (or a file selection if you have code highlighted).
At any point in time, you can edit these context chips, add additional context chips, or remove them completely if you do not want to use these as context. Any chat without a context chip will instruct Cody to use no codebase context. However, you can always provide an alternate @-mention
file to let Cody use it as a new context source.
When you have both a repository and files @-mentioned, Cody will search the repository for context while prioritizing the mentioned files.
Rerun prompts with different context
If Cody's answer isn't helpful, you can try asking again with a different context:
- Public knowledge only: Cody will not use your code files as context; it’ll only use knowledge trained into the base model.
- Current file only: Rerun the prompt using just the current file as context.
- Add context: Provides @-mention context options to improve the response by explicitly including files, remote repositories, or web pages (URL).
Context fetching mechanism
JetBrains users on the Free or Pro plan use local context.
Enterprise users can leverage the full power of the Sourcegraph search engine as Cody's primary context provider.
Context sources
You can @-mention files and web pages in Cody. Cody Enterprise also supports @-mentioning repositories to search for context in a broader scope.
Cody Context Filters
>=6.0.0
.Admins on the Sourcegraph Enterprise instance can use Cody Context Filters to determine which repositories Cody can use as the context in its requests to third-party LLMs. Inside your site configuration, you can define a set of include
and exclude
rules that will be used to filter the list of repositories Cody can access.
For repos mentioned in the exclude
field, Cody prompts are disabled, and you cannot use them for context fetching. If you try running any of these, you'll be prompted with an error message. However, Cody chat will still work, and you can use it to ask questions.
Read more about Cody Context Filters here →
Autocomplete
Cody provides multi-line autocomplete as you type. Autocomplete suggestions appear as inlay suggestions and are enabled by default in your JetBrains IDE. This setting lists the 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
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.
In addition, you can use the following keyboard shortcuts to interact with Cody's autocomplete suggestions:
Tab
to accept a suggestionAlt + [
(Windows) orOpt + [
(macOS) to cycle suggestionsAlt + \
(Windows) orOpt + \
(macOS) to manually trigger autocomplete if no suggestions have been returned
Prompts
Cody allows you create quick, ready-to-use prompts to automate key tasks in your workflow. Prompts are created and saved in the Prompt Library and can be accessed from the Tools > Prompt Library in the top navigation bar in your Sourcegraph instance.
To help you get started, there are a few prompts that are available by default. These can assist you to:
- Document code
- Explain code
- Detect code smells
- Generate unit tests
Inline code edits
You can directly perform inline edits on your code without opening the chat window.
- Select the code you want to edit
- Then right-click and select Cody > Edit Code
- Alternatively, you can press Opt+K (macOS) or Alt+K (Windows) to open the inline editor
Here, you can describe the change you want to make and select the LLM model you want to use.
Once you enter your prompt, Cody will perform inline edits that you can Accept, Undo, or Show diff for the change. Click Edit & Retry to iterate your prompt and get alternate suggestions.
Inline code fix
Cody with JetBrains can also propose fixes and updates to errors in your code. The inline Ask Cody to Fix functionality alerts a user when it notices an issue. It provides a workflow to suggest a fix, review the suggestion, and accept the change, all within the editor.
All you need to do is select and highlight the code line with the error and click the lightbulb icon. Then select Ask Cody to Fix. You can then view the diff and accept or undo the suggested change.
Updating the plugin
JetBrains IDEs will typically notify you when updates are available for installed plugins. Follow the prompts to update the Cody AI plugin to the latest version.
Change the update channel for stable or nightly releases
Our nightly release channel gets updated much more frequently, which might help verify bug fixes that will be included in the next stable release. To update your update channel, you can do the following:
- Open your JetBrains IDE settings by selecting IDE Name | Settings on macOS or File | Settings on Windows and Linux from the main menu.
- Get to the Cody Settings by navigating to
Tools -> Sourcegraph & Cody
- Under the update channel, select
Stable
orNightly
Supported LLM models
Cody Free and Pro users can choose from a list of supported LLM models for chat.
Enterprise users who have model configuration configured can also select from the available models for their instance. On instances with the "completions" configuration, a site admin determines the LLM, which cannot be changed within the editor.
Ollama model support
You can use Ollama models locally for Cody’s chat. This lets you chat without sending messages over the internet to an LLM provider so that you can use Cody offline. To use Ollama locally, you’ll need to install Ollama and download a chat model such as CodeGemma or Llama3. Read here for detailed instructions.
Add/remove account
To add or remove an account, you can do the following:
- Open Cody by clicking the Cody icon on the toolbar
- On the open sidebar, select the Account icon
- Select
Sign Out
to remove an account
Alternatively, you can also manage multiple accounts in Cody Settings:
- Open your IDE settings by selecting IDE | Settings on macOS or File | Settings on Windows and Linux from the main menu.
- Go to the Cody Settings by navigating to
Tools -> Sourcegraph & Cody
- Under authentication, see the accounts that are currently logged in
- To remove, select your account and hit
-
. To add click+
and choose the appropriate login method
Find Cody features
You can find and discover all Cody features and actions using the Search Everywhere option in JetBrains IDEs. Press Shift
twice to open the Search Everywhere
window. Then, type in the Cody:
prefix to get a list of all supported Cody actions.