Skip to content

Sourcegraph extension to open the currently viewed file in IntelliJ IDEA

License

Notifications You must be signed in to change notification settings

sourcegraph/sourcegraph-open-in-intellij

Repository files navigation

Open in Intellij Sourcegraph extension

⚠️ Deprecation notice

Sourcegraph extensions have been deprecated with the September 2022 Sourcegraph release. Learn more.

The repo and the docs below are kept to support older Sourcegraph versions.

Description

Adds a button to the Sourcegraph's extension panel and at the top of files in code hosts like GitHub (when the Sourcegraph browser extension is installed) that will open the current file in Intellij.

Screenshot

Configuration

This extension requires all git repos to be cloned and available on your local machine.

Please add the following options in your Sourcegraph's User Settings to configure the extension:

  • openInIntellij.basePath: [REQUIRED] String. The absolute path on your computer where your git repositories live. The extension will try to open the file in a clone named by the last segment of the repository name in that folder. This extension requires all git repos to be already cloned under this path with their original names, which the final path can later be altered using the openInIntellij.replacements option.

    • Note: "/Users/yourusername/src" is a valid absolute path, while "~/src" is not.
  • openInIntellij.useBuiltin: [OPTIONAL] Boolean. Set option to true in your user settings if you would like to open files using the Intellij's built-in REST API, or if you are using this extension on Windows.

  • openInIntellij.replacements: [OPTIONAL] Set to an object that includes pairs of strings, where each key will be replaced by its value in the final url. The key can be a string or a RegExp, and the value must be a string. For example, using "openInIntellij.replacements": {"(?<=Documents\/)(.*[\\\/])": "sourcegraph-$1"} will add sourcegraph- in front of the string that matches the (?<=Documents\/)(.*[\\\/]) RegExp pattern, while "openInIntellij.replacements": {"sourcegraph-": ""} will remove sourcegraph- from the final URL.

  • openInIntellij.osPaths: [OPTIONAL] Takes object. The extension uses the assigned path for the detected Operating System when available. If no platform is detected then we will keep using the basePath provided by openInIntellij.basePath.

    • Note: Currently support "windows", "mac", and "linux" as keys.

Configuration for Windows users

The idea:// protocol handler that this extension is using to open files directly from a URL is currently not supported on Windows. As a workaround, Windows user can use the Intellij's built-in REST API to open files directly from a URL with extra configuration steps.

  1. In the Intellij's Settings panel, go to Build, Execution, Deployment

  2. Click on the Debugger tab and mark the box next to Allow unsigned requests as checked. This allows requests to be made to the built-in server from outside IntelliJ IDEA as stated in their docs

  3. Intellij must be remained open for this workaround to work.

Examples

Mac

To open repository files in your Documents directory:

{
  "extensions": {
    "sourcegraph/open-in-intellij": true,
  },
  "openInIntellij.basePath": "/Users/USERNAME/Documents/"
}

Windows

To open repository files in your user's IdeaProjects directory:

{
  "extensions": {
    "sourcegraph/open-in-intellij": true,
  },
  "openInIntellij.basePath": "/C:/Users/USERNAME/IdeaProjects/",
  "openInIntellij.useBuiltin": true,
}

Set basePath for multiple platforms

Uses the assigned path for the detected Operating System when available:

{
  "extensions": {
    "sourcegraph/open-in-intellij": true,
  },
  "openInIntellij.osPaths": {
    // useBuiltin will automatically be set to true for windows
    "windows": "/C:/Users/USERNAME/folder/",
    "mac": "/Users/USERNAME/folder/",
    "linux": "/home/USERNAME/folder/"
  },
  // set basePath as fallback path when no operating system is detected
  "openInIntellij.basePath": "/Users/USERNAME/Documents/"
}

Development

  1. Run yarn && yarn run serve and keep the Parcel bundler process running
  2. Sideload the extension (at the URL http://localhost:1234 by default) on your Sourcegraph instance or Sourcegraph.com

When you edit a source file in your editor, Parcel will recompile the extension. Reload the Sourcegraph web page to use the updated extension.

About

Sourcegraph extension to open the currently viewed file in IntelliJ IDEA

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published