Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IntellJ IDEA, VSCode, and VSCodium. Also fix typo #51

Merged
merged 6 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/Open/This.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use strict;
use warnings;

package Open::This;

our $VERSION = '0.000033';
Expand Down Expand Up @@ -121,7 +122,8 @@ sub maybe_get_url_from_parsed_text {
my $clone = $url->clone;
my @parts = $clone->path_segments;
push(
@parts, 'blob', Git::Helpers::current_branch_name(),
@parts,
'blob', Git::Helpers::current_branch_name(),
$parsed->{file_name}
);
$clone->path( join '/', @parts );
Expand All @@ -144,14 +146,31 @@ sub editor_args_from_parsed_text {
my @args;

# kate --line 11 --column 2 filename
if ( $ENV{EDITOR} eq 'kate' ) {
# idea.sh --line 11 --column 2 filename
if ( $ENV{EDITOR} eq 'kate'
|| $ENV{EDITOR}
=~ /^(idea|rubymine|pycharm|phpstorm|webstorm|goland|rider|clion|fleet|aqua|data(grip|spell)|appcode)/i
) {
push @args, '--line', $parsed->{line_number}
if $parsed->{line_number};

push @args, '--column', $parsed->{column_number}
if $parsed->{column_number};
}

# code --goto filename:11:2
# codium --goto filename:11:2
elsif ( $ENV{EDITOR} =~ /^cod(e|ium)/i ) {
my $result = $parsed->{file_name};
if ( $parsed->{line_number} ) {
$result .= ":" . $parsed->{line_number};
if ( $parsed->{column_number} ) {
$result .= ":" . $parsed->{column_number};
}
}
return ( '--goto', $result );
}

# See https://vi.stackexchange.com/questions/18499/can-i-open-a-file-at-an-arbitrary-line-and-column-via-the-command-line
# nvim +'call cursor(11,2)' filename
# vi +'call cursor(11,2)' filename
Expand Down
4 changes: 2 additions & 2 deletions script/ot
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ disks. All security caveats apply when requiring 3rd party modules.
ot -e kate Foo::Bar

# Don't open anything. Just print to STDOUT. [-p|--print]
ot -p kate Foo::Bar
ot -p -e kate Foo::Bar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 Good catch!


=head1 PARAMETERS

Expand Down Expand Up @@ -186,7 +186,7 @@ other appropriate place in your dot files.
=head1 SUPPORTED EDITORS

This code has been well tested with C<vim>. It should also work with C<nvim>,
C<emacs>, C<pico>, C<nano> and C<kate>. Patches for other editors are very
C<emacs>, C<pico>, C<nano>, IntelliJ IDEA, Visual Studio Code, VSCodium and C<kate>. Patches for other editors are very
welcome.

=cut
32 changes: 32 additions & 0 deletions t/intellij.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env perl

use strict;
use warnings;

use Open::This qw( to_editor_args );
use Test::Differences qw( eq_or_diff );
use Test::More import => [qw( done_testing )];
use Test::Warnings ();

my @editors = ( 'idea', 'idea.sh', 'idea64', 'idea64.exe' );

for my $editor (@editors) {

local $ENV{EDITOR} = $editor;

eq_or_diff( [ to_editor_args('t/git.t') ], [ 't/git.t', ], 'filename' );

eq_or_diff(
[ to_editor_args('t/git.t:10') ],
[ '--line', '10', 't/git.t', ], 'line'
);

eq_or_diff(
[ to_editor_args('t/git.t:10:22') ],
[ '--line', '10', '--column', '22', 't/git.t', ],
'line and column'
);

}

done_testing();
36 changes: 36 additions & 0 deletions t/vscode_family.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env perl

use strict;
use warnings;

use Open::This qw( to_editor_args );
use Test::Differences qw( eq_or_diff );
use Test::More import => [qw( done_testing )];
use Test::Warnings ();

my @editors = ( 'code', 'codium' );

for my $editor (@editors) {

local $ENV{EDITOR} = $editor;

eq_or_diff(
[ to_editor_args('t/git.t') ],
[ '--goto', 't/git.t', ],
$editor . ' filename'
);

eq_or_diff(
[ to_editor_args('t/git.t:10') ],
[ '--goto', 't/git.t:10', ],
$editor . ' line'
);

eq_or_diff(
[ to_editor_args('t/git.t:10:22') ],
[ '--goto', 't/git.t:10:22', ],
$editor . ' line and column'
);

}
done_testing();