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

Conversation

mcneb10
Copy link
Contributor

@mcneb10 mcneb10 commented Aug 9, 2023

No description provided.

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 9, 2023

I'm a little confused why the tidyall check is failing. I ran perltidy (with the perltidyrc) on all the files I created/changed

@oalders
Copy link
Member

oalders commented Aug 9, 2023

I'm a little confused why the tidyall check is failing. I ran perltidy (with the perltidyrc) on all the files I created/changed

Which version of perltidy do you have installed?

@oalders
Copy link
Member

oalders commented Aug 9, 2023

This is what I get with

perltidy --version
This is perltidy, v20230701

diff --git a/lib/Open/This.pm b/lib/Open/This.pm
index b261e1c..4267a95 100644
--- a/lib/Open/This.pm
+++ b/lib/Open/This.pm
@@ -7,16 +7,16 @@ our $VERSION = '0.000033';
 
 our @ISA       = qw(Exporter);
 our @EXPORT_OK = qw(
-  maybe_get_url_from_parsed_text
-  editor_args_from_parsed_text
-  parse_text
-  to_editor_args
+    maybe_get_url_from_parsed_text
+    editor_args_from_parsed_text
+    parse_text
+    to_editor_args
 );
 
 use Module::Runtime qw(
-  is_module_name
-  module_notional_filename
-  require_module
+    is_module_name
+    module_notional_filename
+    require_module
 );
 use Module::Util ();
 use Path::Tiny   qw( path );
@@ -86,13 +86,14 @@ sub parse_text {
     }
 
     if ( !$parsed{line_number} ) {
-        $parsed{line_number} =
-          _maybe_extract_line_number_via_sub_name( $parsed{file_name},
-            $parsed{sub_name} );
+        $parsed{line_number} = _maybe_extract_line_number_via_sub_name(
+            $parsed{file_name},
+            $parsed{sub_name}
+        );
     }
 
     my %return = map { $_ => $parsed{$_} }
-      grep { defined $parsed{$_} && $parsed{$_} ne q{} } keys %parsed;
+        grep { defined $parsed{$_} && $parsed{$_} ne q{} } keys %parsed;
 
     return $return{file_name} ? \%return : undef;
 }
@@ -120,9 +121,11 @@ sub maybe_get_url_from_parsed_text {
 
     my $clone = $url->clone;
     my @parts = $clone->path_segments;
-    push( @parts,
+    push(
+        @parts,
         'blob', Git::Helpers::current_branch_name(),
-        $parsed->{file_name} );
+        $parsed->{file_name}
+    );
     $clone->path( join '/', @parts );
     if ( $parsed->{line_number} ) {
         $clone->fragment( 'L' . $parsed->{line_number} );
@@ -146,10 +149,10 @@ sub editor_args_from_parsed_text {
     # idea.sh --line 11 --column 2 filename
     if ( $ENV{EDITOR} eq 'kate' || $ENV{EDITOR} =~ /^idea/i ) {
         push @args, '--line', $parsed->{line_number}
-          if $parsed->{line_number};
+            if $parsed->{line_number};
 
         push @args, '--column', $parsed->{column_number}
-          if $parsed->{column_number};
+            if $parsed->{column_number};
     }
 
     # code filename:11:2
@@ -165,15 +168,14 @@ sub editor_args_from_parsed_text {
         return ($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
-# vim  +'call cursor(11,2)' filename
+    # 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
+    # vim  +'call cursor(11,2)' filename
     elsif ( exists $parsed->{column_number} ) {
         if (   $ENV{EDITOR} eq 'nvim'
             || $ENV{EDITOR} eq 'vi'
-            || $ENV{EDITOR} eq 'vim' )
-        {
+            || $ENV{EDITOR} eq 'vim' ) {
             @args = sprintf(
                 '+call cursor(%i,%i)',
                 $parsed->{line_number},
@@ -183,7 +185,8 @@ sub editor_args_from_parsed_text {
 
         # nano +11,2 filename
         if ( $ENV{EDITOR} eq 'nano' ) {
-            @args = sprintf( '+%i,%i',
+            @args = sprintf(
+                '+%i,%i',
                 $parsed->{line_number},
                 $parsed->{column_number},
             );
@@ -312,10 +315,10 @@ sub _maybe_extract_file_from_url {
 sub _maybe_find_local_file {
     my $text          = shift;
     my $possible_name = module_notional_filename($text);
-    my @dirs =
-      exists $ENV{OPEN_THIS_LIBS}
-      ? split m{,}, $ENV{OPEN_THIS_LIBS}
-      : ( 'lib', 't/lib' );
+    my @dirs
+        = exists $ENV{OPEN_THIS_LIBS}
+        ? split m{,}, $ENV{OPEN_THIS_LIBS}
+        : ( 'lib', 't/lib' );
 
     for my $dir (@dirs) {
         my $path = path( $dir, $possible_name );
@@ -369,7 +372,7 @@ sub _find_go_files {
     while ( my $path = $iter->() ) {
         next unless $path->is_file;    # dirs will never match anything
         ( $threshold, $file_name ) = ( 0, "$path" )
-          if $path->basename eq $text;
+            if $path->basename eq $text;
         last if --$threshold == 0;
     }
     if ( $threshold == 0 && !$file_name ) {
diff --git a/script/ot b/script/ot
index 4d1931c..f1803e2 100755
--- a/script/ot
+++ b/script/ot
@@ -5,9 +5,9 @@ use warnings;
 
 use Getopt::Long qw( GetOptions );
 use Open::This   qw(
-  editor_args_from_parsed_text
-  maybe_get_url_from_parsed_text
-  parse_text
+    editor_args_from_parsed_text
+    maybe_get_url_from_parsed_text
+    parse_text
 );
 use Path::Tiny qw( path );
 use Pod::Usage qw( pod2usage );
@@ -56,8 +56,8 @@ if ($print) {
 }
 
 $ENV{EDITOR}
-  ? exec $ENV{EDITOR}, @editor_args
-  : die('Please set your $EDITOR env var or use the --editor arg');
+    ? exec $ENV{EDITOR}, @editor_args
+    : die('Please set your $EDITOR env var or use the --editor arg');
 
 # ABSTRACT: parse text and (hopefully) open an editor with the correct arguments
 # PODNAME: ot
diff --git a/t/intellij.t b/t/intellij.t
index 4040141..d5a03da 100644
--- a/t/intellij.t
+++ b/t/intellij.t
@@ -16,8 +16,10 @@ for my $editor (@editors) {
 
     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') ],
+        [ '--line', '10', 't/git.t', ], 'line'
+    );
 
     eq_or_diff(
         [ to_editor_args('t/git.t:10:22') ],

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 10, 2023

I get This is perltidy, v20221112
is my version too old?
I'm running it on WSL

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 10, 2023

I just updated PerlTidy, I'll try formatting one more time and see if the check passes

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 10, 2023

there's also an issue with vscode support

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 10, 2023

The documentation on jetbrains' website for IntelliJ seems to be wrong. It says that IntellIJ accepts the same command line arguments as kate, but when I try it on Windows it doesn't work.

@@ -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!

@oalders
Copy link
Member

oalders commented Aug 10, 2023

@mcneb10 thanks so much for this! Is it ready for merge or does it need tweaks for IntelliJ?

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 10, 2023

I'm not quite sure. vscode support has been tested and works fine. vscodium should work as it's just vscode built without branding or telemetry. According to this IntelliJ should work, but doesn't on my machine.

@oalders
Copy link
Member

oalders commented Aug 10, 2023

Maybe @hurricup has some thoughts?

@hurricup
Copy link

Will check in a week, on vacation atm.

@oalders
Copy link
Member

oalders commented Aug 14, 2023

Thanks, enjoy your time away!

@hurricup
Copy link

hurricup commented Aug 26, 2023

@oalders ok. I have a linux machine and my JetBrains tools are installed via Toobox
I have several installations of idea and rubymine.

Toolbox creates a wrapper scripts for all IDE installed. On my machine it looks like:

hurricup@AM-UNIT-0002:~$ rubymine
rubymine   rubymine1  rubymine2  
hurricup@AM-UNIT-0002:~$ idea
idea   idea1  idea2  
hurricup@AM-UNIT-0002:~$ which idea
/home/hurricup/.local/share/JetBrains/Toolbox/scripts/idea

Command idea --line 5 filename starts an editor in the same process and opens file, navigation to the line does not work for some reason, but feels like it is a totally different issue.

So few points on this:

  1. We need to check not only for idea, but more like for idea|rubymine|pycharm|phpstorm|webstorm|goland or JetBrains at least (actually there are more products).
  2. Can't say why it is not working for @mcneb10, need to see the resulting command and local output from running from the terminal.

Created an issue about line navigation: https://youtrack.jetbrains.com/issue/IDEA-330800/Line-navigation-from-the-cli-does-not-work

@mcneb10
Copy link
Contributor Author

mcneb10 commented Aug 28, 2023

I'll add support for the other jetbrains editors soon. Thanks for your help!

@oalders
Copy link
Member

oalders commented Sep 12, 2023

Thanks @mcneb10 and @hurricup!

@oalders oalders merged commit 5a9a2f0 into perl-ide:main Sep 12, 2023
37 checks passed
@oalders
Copy link
Member

oalders commented Sep 12, 2023

This is now on CPAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants