Changeset 5504


Ignore:
Timestamp:
06/23/09 06:14:48 (3 years ago)
Author:
azawawi
Message:

[Perl 6] Comment error line quick fix is always the last one if an error occurs is on the current line
[Perl 6] Finally implemented 'Surround with try { ... }' quick fix. Perl 6 exception handling with indentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6/Perl6Document.pm

    r5502 r5504  
    226226    my @items = (); 
    227227    my $num_issues = scalar @{$self->{issues}}; 
    228     print "Number of issues: $num_issues\n"; 
    229     my $comment_error_added = 0; 
    230228    foreach my $issue ( @{$self->{issues}} ) { 
    231229        my $issue_line_no = $issue->{line} - 1; 
     
    623621            } 
    624622 
    625             if(not $comment_error_added) { 
    626                 push @items, { 
    627                     text     => Wx::gettext('Comment error line'), 
    628                     listener => sub { 
    629                         # comment current error by putting a hash and a space 
    630                         # since #( is an embedded comment in Perl 6! 
    631                         # see S02:166 
    632                         my $line_start = $editor->PositionFromLine( $current_line_no ); 
    633                         $editor->InsertText($line_start, '# '); 
    634                     }, 
    635                 }; 
    636                 $comment_error_added = 1; 
    637             } 
     623        } 
     624 
     625    } 
     626     
     627    if($num_issues) { 
     628         
     629        # add "comment error line" as the last resort to solving an issue 
     630        push @items, { 
     631            text     => Wx::gettext('Comment error line'), 
     632            listener => sub { 
     633                # comment current error by putting a hash and a space 
     634                # since #( is an embedded comment in Perl 6! 
     635                # see S02:166 
     636                my $line_start = $editor->PositionFromLine( $current_line_no ); 
     637                $editor->InsertText($line_start, '# '); 
     638            }, 
     639        }; 
     640         
     641    } else { 
     642 
     643        # No issues; let us provide a some helpful quick fixes 
     644        my $selected_text = $editor->GetSelectedText; 
     645        if($selected_text && $selected_text =~ /[\n\r]/) { 
     646             
     647            push @items, { 
     648                text     => Wx::gettext('Surround with try { ... }'), 
     649                listener => sub { 
     650                    # Surround the 'selection' with a try { 'selection'  CATCH { } } 
     651                    my $line_start = $editor->PositionFromLine(  
     652                        $editor->LineFromPosition($editor->GetSelectionStart)  
     653                    ); 
     654                    my $line_end = $editor->PositionFromLine(  
     655                        $editor->LineFromPosition($editor->GetSelectionEnd)  
     656                    ); 
     657                     
     658                    my $indent = ($selected_text =~ /(^\s+)/) ? $1 : ''; 
     659                    $selected_text =~ s/^/\t/gm; 
     660                    my $line_text =  "${indent}try {\n" . 
     661                        "$selected_text\n" .  
     662                        "${indent}\tCATCH {\n" . 
     663                        "${indent}\t\twarn \"oops: \$!\";\n" . 
     664                        "${indent}\t}\n" . 
     665                        "${indent}}\n"; 
     666                    $editor->SetSelection( $line_start, $line_end ); 
     667                    $editor->ReplaceSelection( $line_text ); 
     668                }, 
     669            }; 
    638670             
    639671        } 
Note: See TracChangeset for help on using the changeset viewer.