iTerm2 icon indicating copy to clipboard operation
iTerm2 copied to clipboard

Support opening to line number in all JetBrains IDEs

Open shawwn opened this issue 4 years ago • 7 comments

From iTerm's documentation:

If you hold cmd and click on a URL it will be opened. If you hold cmd and click on a filename, it will be opened. There is special support for MacVim, TextMate, and BBEdit when you cmd-click on a text file's name: if it is followed by a colon and line number, the file will be opened at that line number.

Currently, iTerm can open to line number for IDEA, but it doesn't support any other IntelliJ editors like WebStorm, PyCharm, etc.

This PR implements support for every JetBrains IDE, since they can all handle the --line argument on command line.

The one tricky change was:

- (void)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier args:(NSArray *)args {
    args = [@[ @"-nb", bundleIdentifier, @"--args" ] arrayByAddingObjectsFromArray: args];
    [self launchTaskWithPath:@"/usr/bin/open" arguments:args completion:nil];
}

In order to open JetBrains IDEs correctly, it's necessary to use e.g. open -nb com.jetbrains.WebStorm --args --line 4 index.js. Simply invoking the executable directly will result in strange errors. (Note that their official docs use open -n: https://www.jetbrains.com/help/pycharm/working-with-the-ide-features-from-command-line.html#toolbox)

shawwn avatar Nov 04 '21 11:11 shawwn

It's hard to know what effect this change will have. I would recommend using the new method of opening only for JetBrains IDEs and leave it alone for all other apps.

gnachman avatar Nov 05 '21 21:11 gnachman

This would be amazing! I’m using JetBrains Rider and would love to have goto-line.

lydell avatar Oct 02 '22 09:10 lydell

I've merged a commit based on this, but open -nb com.jetbrains.WebStorm --args --line 4 file.js doesn't seem to work. It's fine for Rider though. Let me know if there's another JetBrains IDE I should add support for.

gnachman avatar Oct 04 '22 00:10 gnachman

Awesome! Rider is the only one I need currently.

lydell avatar Oct 09 '22 14:10 lydell

Could --column 123 be added if there's another colon and number present? That is, with a file name like /path/to/file:LINE:COLUMN. Some tools emit this enhanced format.

Unfortunately, to implement this cleanly a breaking change would have to be made which should be clearly announced in advance, given that the \3 substitution token (which would be the natural candidate for this improvement) sadly wasn't reserved for this purpose and is already in use. \6 could be used instead but that's ugly given that line and column numbers naturally belong together.

josb avatar Sep 10 '23 22:09 josb

@josb Sorry,for which editor(s)?

gnachman avatar Sep 30 '23 22:09 gnachman

@gnachman I imagine all JetBrains IDEs support this option, but in my case I am specifically talking about IntelliJ IDEA Ultimate.

josb avatar Oct 01 '23 05:10 josb