- New: Search with Sourcegraph directly from inside the IDE
- Instantly search in all open source repos and your private code
- Peek into any remote repo in the IDE, without checking it out locally
- Create URLs to specific code blocks to share them with your teammates
- Open your files on Sourcegraph
The plugin works with all JetBrains IDEs, including:
- IntelliJ IDEA
- IntelliJ IDEA Community Edition
- PhpStorm
- WebStorm
- PyCharm
- PyCharm Community Edition
- RubyMine
- AppCode
- CLion
- GoLand
- DataGrip
- Rider
- Android Studio
Exception: Due to a Java bug, search doesn't work with IDE versions 2021.1 and 2021.2 for users with Apple Silicone CPUs.
- Open settings
- Windows: Go to
File | Settings(or use Ctrl+Alt+S) - Mac: Go to
IntelliJ IDEA | Preferences(or use ⌘,)
- Windows: Go to
- Click
Pluginsin the left-hand pane, then theMarketplacetab at the top - Search for
Sourcegraph, then click theInstallbutton - Make sure that the
gitcommand is available in your PATH. We’re going to get rid of this dependency, but for now, the plugin relies on it. - Restart your IDE if needed
- To search with Sourcegraph, press Alt+S (⌥S on Mac).
- To share a link to your code or search through the website, right-click in the editor, and choose an action under the
Sourcegraphcontext menu item. - To use your private Sourcegraph instance, open
Settings | Tools | Sourcegraphand enter your URL and access token.
You can configure the plugin on three levels:
- Project-level settings take the highest priority.
- Application-level settings are second: For each specific setting, if the plugin finds no project-level value, then the app-level setting is used.
- User-level (legacy) settings take the lowest priority. Also, note that only three of the settings are available on the user level.
Here is each level in detail.
These settings have the highest priority. You can set them in a less than intuitive way:
- Create a new file at
{project root}/.idea/sourcegraph.xmlif it doesn't exist, with this content:If the file already exists, then just add the option lines next to the original ones.<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="Config"> <option name="instanceType" value="DOTCOM" /> <option name="url" value="https://company.sourcegraph.com/" /> <option name="accessToken" value="" /> <option name="defaultBranch" value="main" /> <option name="remoteUrlReplacements" value="" /> <option name="isGlobbingEnabled" value="false" /> </component> </project>
- Reopen your project to let the IDE catch up with the changes. Now you have custom settings enabled for this project. In the future, when you have this project open and you edit your settings in the Settings UI, they will be saved to the project-level file.
- To remove the project-level settings, open the XML again and remove the lines you want to set on the app level.
Storage location: {project root}/.idea/sourcegraph.xml
This is what you edit when you go to Settings and make changes in the UI. That is, unless you have project-specific settings for your current project.
Storage location: App-level settings are stored in a file called sourcegraph.xml together with the rest of the IDE settings. This article will help you find it if you should need it for anything.
This type of settings take the lowest priority, and is something that's rarely used and is only kept for backwards compatibility, and might be removed in the future. So, the plugin is also configurable by removing all creating a file called .sourcegraph-jetbrains.properties in your home directory. Both the app-level and project-level XMLs override this, plus it only supports three settings:
url = https://sourcegraph.example.com
defaultBranch = example-branch
remoteUrlReplacements = git.example.com, git-web.example.com
By default, the plugin will use the git remote called origin to determine which repository on Sourcegraph corresponds to your local repository. If your origin remote doesn’t match Sourcegraph, you may instead configure a Git remote by the name of sourcegraph. It will take priority when creating Sourcegraph links.
You can configure JetBrains to set custom keymaps for Sourcegraph actions:
- Open the JetBrains preferences panel and go to to the Keymap page.
- Filter by "sourcegraph" to see actions supplied by this plugin.
- Now select an option to overwrite the keymap information and supply the new bindings.
If you have any questions, feedback, or bug report, we appreciate if you open an issue on GitHub.
- Open settings
- Windows: Go to
File | Settings(or use Ctrl+Alt+S) - Mac: Go to
IntelliJ IDEA | Preferences(or use ⌘,)
- Windows: Go to
- Click
Pluginsin the left-hand pane, then theInstalledtab at the top - Find
Sourcegraph→ Right click →Uninstall(or uncheck to disable)
- Clone
https://github.com/sourcegraph/sourcegraph(on Windows, you'll need to use WSL2) - Run
yarn installin the root directory to get all dependencies - Run
yarn generatein the root directory to generate graphql files - Go to
client/jetbrains/and runyarn buildto generate the JS files, oryarn watchto watch for changes and regenerate on the fly - You can test the “Find with Sourcegraph” window by running
yarn standalonein theclient/jetbrains/directory and opening http://localhost:3000/ in your browser. - Run the plugin in a sandboxed IDE by running
./gradlew runIde. This will start the platform with the versions defined ingradle.properties, here.- Note: 2021.3 or later is required for Macs with Apple Silicon chips.
- Build a deployable plugin artifact by running
./gradlew buildPlugin. The output file isbuild/distributions/Sourcegraph.zip.
The publishing process is based on the intellij-platform-plugin-template.
- Update
pluginVersioningradle.properties- To create pre-release builds with the same version as a previous one, append
.{N}. For example,1.0.0-alpha, then1.0.0-alpha.1,1.0.0-alpha.2, and so on.
- To create pre-release builds with the same version as a previous one, append
- Describe the changes in the
[Unreleased]section ofclient/jetbrains/CHANGELOG.md - Run
PUBLISH_TOKEN=<YOUR TOKEN HERE> ./scripts/release.shfrom inside theclient/jetbrainsdirectory (You can generate tokens on the JetBrains marketplace).
See CHANGELOG.md.
Parts of this extension rely on the JCEF web view features built into the JetBrains platform. To enable debugging tools for this view, please follow these steps:
- Enable JetBrains internal mode
- Open Find Actions: (Ctrl+Shift+A / ⌘⇧A)
- Search for "Registry..." and open it
- Find option
ide.browser.jcef.debug.port - Change the default value to an open port (we use
9222) - Restart IDE
- Open the “Find with Sourcegraph” window (Alt+A / ⌥A)
- Switch to a browser window, go to
localhost:9222, and select the Sourcegraph window. Sometimes it needs some back and forth to focus the external browser with the JCEF component also focused—you may need to move the popup out of the way and click the external browser rather than using Alt+Tab / ⌘Tab.
