14

Example, qbittorent can be made to open links that are of torrent files.

Email clients mailto:

Is it possible to create links in a browser that will open the given file in Intellij? (Not full path, but entire package possibly ).

Idea is that this will be created for bitbucket.

3 Answers 3

21

There is an open feature request to add idea:// protocol handler.

At the moment it works on macOS only out of the box. For other platforms you can try the third-party solution or other workarounds from the ticket comments.

There is also a built-in web server providing the REST API to open files.

It will work with the relative paths only when the IDE is already running and the project is open: http://localhost:63342/api/file/relative/to/module/root/path/to/file.kt.

With the JetBrains Toolbox App installed one will be able to use jetbrains:// protocol for navigation, it's work in progress and should be available in 2019.2.

See JBProtocolNavigateCommand.kt for the reference:

// handles URLs of the following types:

// jetbrains://idea/navigate/reference?project=IDEA
// [&reference[X]=com.intellij.navigation.JBProtocolNavigateCommand[.perform][#perform]]+
// [&path[X]=com/intellij/openapi/project/impl/JBProtocolNavigateCommand.kt[:23[:1]]]+
// [&selection[X]=25:5-26:6]+

Sample URL:

jetbrains://idea/navigate/reference?project=IDEA&fqn=com.intellij.openapi.application.JetBrainsProtocolHandler#getParameters

Toolbox URL matches regexp:

"${JetBrainsProtocolHandler.PROTOCOL}([\\w\\-]+)/navigate/reference\\?project=(?<project>[\\w]+)(&fqn[\\d]*=(?<fqn>[\\w.\\-#]+))*(&path[\\d]*=(?<path>[\\w-_/\\\\.]+)(:(?<location1>[\\d]+))?(:(?<location2>[\\d]+))?)*(&selection[\\d]*=(?<line1>[\\d]+):(?<column1>[\\d]+)-(?<line2>[\\d]+):(?<column2>[\\d]+))*"

There will be also UI for copying TBX protocol URLs directly from the editor similar to the Copy Reference action in the context menu. The same will work for IDE settings navigation.

18
  • issue number one. Relative path to module root might be a bit problematic. There should be a best match opener functionality. Not always you have the path or can figure it out properly, depending on where the project might on disc.
    – mjs
    May 10, 2019 at 12:33
  • It should work like that in 2019.2 with the project reference and fqn. You don't have to specify the exact path, IDE will perform the search.
    – CrazyCoder
    May 10, 2019 at 19:50
  • I am on mac. On 2019.2 now. Trying the various links. I Have a file in maven module relative to a workspace path/to/workspace/projects/myproject/src/main/java/my.package/MyClass.java Can you provide me with a full url example, because I am unable to get anything to open.
    – mjs
    May 17, 2019 at 8:16
  • @momomo 2019.2 is not released yet.
    – CrazyCoder
    May 17, 2019 at 8:17
  • The localhost approach does trigger intellij (albeit with constant popup annoyance about trusting unknown ... ) but doesn't open the relevant file.
    – mjs
    May 17, 2019 at 8:17
1

As an update to @CrazyCoder's answer

This works* on Mac currently. (unable to test on anything else personally)

* There are some issues:

  • There is no context menu option for generating this link from clicking on a line of code
  • The keybinding (see below) generates the incorrect path, and it needs to be modified manually by either changing the sources root temporarily, or typing the missing path parts by hand.

There is a keybinding you can use to generate the url, under Preferences > Keymap > Copy Path/Reference > Toolbox URL. Note that the cursor location when using the keybinding matters. From what I can tell, if the cursor is at the beginning or end of a line, it generates a url with &path=..., else it generates with &fqn=.... The fqn option will often link to the wrong area of the code, especially when interfaces, libraries, auto-wiring, or anything not a direct vanilla class/object/function is attempted to link to.

I have filed an issue with more details on the broken path generated by the keybinding: https://youtrack.jetbrains.com/issue/IDEA-290640

-1

I have created my custom (unofficial) "jb://" scheme, that can open file from the specified project.

I use it in the git-mediawiki project. After cloning the wiki page, I want to open it as a project in Writerside.

This is the URL example shown by git-mediawiki utility (I will place it in several lines to simplify reading):

jb://localhost?api=v1
&ide=writerside
&project_path=~/Documents/MediaWiki/
&file_path=wiki.blender.org/Building_Blender/Linux/Arch/Arch.mw

In this case, the ~/Documents/MediaWiki/ is a directory with the .idea folder. This is a multi-root project. The folder ~/Documents/MediaWiki/wiki.blender.org/Building_Blender/Linux/Arch/ contains a .git folder, and the Arch.mw is a file from that repo.

So after installing the jb-url-handler and clicking that link, the Writerside will open (if not yet), and the tab with file Arch.mw will be opened.

See https://github.com/Ashark/jb-url-handler.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.