Skip to content

Commit

Permalink
Implement step-in (stage 2)... some bugs still lurk
Browse files Browse the repository at this point in the history
  • Loading branch information
azawawi committed Nov 4, 2014
1 parent c2ad0bc commit a7e254e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 12 deletions.
10 changes: 8 additions & 2 deletions lib/Farabi6.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@ method run(Str $host, Int $port, Bool $verbose) is export {
return Farabi6::Editor.help-search(
Farabi6::Util.get-parameter(%env<psgi.input>.decode, 'pattern'));
}
when '/debug/status' {
return Farabi6::Editor.debug-status(
Farabi6::Util.get-parameter(%env<psgi.input>.decode, 'id')
);
}
when '/debug/step_in' {
my %params = Farabi6::Util.params(%env<psgi.input>);
return Farabi6::Editor.debug-step-in(
Farabi6::Util.get-parameter(%env<psgi.input>.decode, 'debug_session_id'),
Farabi6::Util.get-parameter(%env<psgi.input>.decode, 'source')
%params<id>,
%params<source>
);
}
when '/debug/step_out' {
Expand Down
74 changes: 65 additions & 9 deletions lib/Farabi6/Editor.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ method help-search(Str $pattern is copy) {
}

my %debug_sessions;
my $debug_session_id;
my $debug_session_id = 0;

=begin comment
Expand Down Expand Up @@ -553,11 +553,14 @@ method start-debugging-session(Str $source)
# Start debugging the temporary script
my $pc = Proc::Async.new( "perl6-debug-m", [$filename], :w );

my $result_session_id = $debug_session_id;
my Str $result_session_id = ~$debug_session_id;
$debug_session_id++;

# Record debug session
%debug_sessions{$result_session_id} = $pc;
$debug_session_id++;
%debug_sessions{$result_session_id} = (
pc => $pc,
results => [],
);

my $so = $pc.stdout;
my $se = $pc.stderr;
Expand Down Expand Up @@ -607,7 +610,8 @@ method start-debugging-session(Str $source)
}
};

%debug_sessions<$result_session_id><'results'> = @results;
my $session = %debug_sessions{$result_session_id};
%$session<results> = @results;

say "result: $_" for @results;
}
Expand All @@ -617,7 +621,9 @@ method start-debugging-session(Str $source)
}

my $pm = $pc.start;


say %debug_sessions;

return $result_session_id,
}

Expand All @@ -627,21 +633,71 @@ method start-debugging-session(Str $source)
Step in
=end comment
method debug-step-in(Str $debug-session-id, Str $source)
method debug-step-in(Str $debug-session-id is copy, Str $source)
{
unless $debug-session-id
say %debug_sessions;
say "debug-session-id = $debug-session-id";
my $session = %debug_sessions{$debug-session-id};
if $session.defined
{
# Valid session, let us print to it
my $pc = %$session<pc>;
say $pc;
my $ppr = $pc.print("\n");
await $ppr;
}
else
{
$debug-session-id = self.start-debugging-session($source);
$session = %debug_sessions{$debug-session-id};
}


[
200,
[ 'Content-Type' => 'application/json' ],
[
to-json(
%(
'id' => $debug-session-id,
'results' => %$session<results>,
)
)
],
];
}

=begin comment
Step in
=end comment
method debug-status(Str $debug-session-id)
{

say "debug-session-id = $debug-session-id";
say %debug_sessions;

my $session = %debug_sessions{$debug-session-id};
my @results;

if $session.defined {
@results = %$session<results>;
} else {
@results = [];
}

say %$session;

return
[
200,
[ 'Content-Type' => 'application/json' ],
[
to-json(
%(
'id' => $debug-session-id,
'results' => %debug_sessions<$debug-session-id><'results'>,
'results' => @results,
)
)
],
Expand Down
15 changes: 15 additions & 0 deletions lib/Farabi6/Util.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ constant %ANSI_COLORS = %(
47 => "ansi-bg-white",
);

# Adapted from https://github.com/tadzik/Bailador/blob/master/lib/Bailador/Request.pm
method params($psgi_input)
{
return {} unless $psgi_input;

my %ret;
for $psgi_input.decode.split('&') -> $p
{
my $pair = $p.split('=', 2);
%ret{$pair[0]} = uri_unescape $pair[1];
}

return %ret;
}

method get-parameter(Str $input, Str $name) {
# TODO more generic parameter parsing
my $value = $input;
Expand Down
11 changes: 10 additions & 1 deletion lib/Farabi6/files/assets/farabi.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,19 @@ start: function() {
}
);

var currentDebugSessionId = -1;
$(".debug_step_in_button").click(function() {
$.post('/debug/step_in', {"source": currentEditor.getValue() }, function(result) {
$.post('/debug/step_in', {"id": currentDebugSessionId, "source": currentEditor.getValue() }, function(result) {
console.error(result);

// Check every one second for changes
setInterval(function() {
$.post('/debug/status', { "id": result.id }, function(result) {
console.error(result);
});
}, 1000);
});

});

$(".debug_step_out_button").click(function() {
Expand Down

0 comments on commit a7e254e

Please sign in to comment.