Skip to content

Commit 3148f14

Browse files
indutnyry
authored andcommitted
[debugger] fix 'debug> connecting...', fixed autostart (XXX figure out why it wasn't working in some cases), fixed highlighting for first line of module's code
1 parent 320cf72 commit 3148f14

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

lib/_debugger.js

+50-18
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,11 @@ function SourceInfo(body) {
682682

683683
if (body.script) {
684684
if (body.script.name) {
685-
result += ', ' + body.script.name;
685+
var name = body.script.name;
686+
687+
// TODO Change path to relative, if possible
688+
689+
result += ', ' + name;
686690
} else {
687691
result += ', [unnamed]';
688692
}
@@ -718,7 +722,8 @@ function Interface() {
718722
var proto = Interface.prototype,
719723
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
720724
'requireConnection', 'killChild', 'trySpawn',
721-
'controlEval', 'debugEval', 'print', 'childPrint'],
725+
'controlEval', 'debugEval', 'print', 'childPrint',
726+
'clearline'],
722727
shortcut = {
723728
'run': 'r',
724729
'cont': 'c',
@@ -762,7 +767,16 @@ function Interface() {
762767
this.breakpoints = [];
763768

764769
// Run script automatically
765-
this.run();
770+
this.clearline();
771+
this.pause();
772+
773+
// XXX Need to figure out why we need this delay
774+
setTimeout(function() {
775+
776+
self.run(function() {
777+
self.resume();
778+
});
779+
}, 10);
766780
};
767781

768782

@@ -790,15 +804,24 @@ Interface.prototype.resume = function(silent) {
790804
};
791805

792806

793-
// Print text to output stream
794-
Interface.prototype.print = function(text) {
795-
if (this.killed) return;
807+
// Clear current line
808+
Interface.prototype.clearline = function() {
796809
if (process.stdout.isTTY) {
797810
process.stdout.cursorTo(0);
798811
process.stdout.clearLine(1);
799812
}
813+
};
814+
815+
// Print text to output stream
816+
Interface.prototype.print = function(text, oneline) {
817+
if (this.killed) return;
818+
this.clearline();
819+
800820
process.stdout.write(typeof text === 'string' ? text : util.inspect(text));
801-
process.stdout.write('\n');
821+
822+
if (oneline !== true) {
823+
process.stdout.write('\n');
824+
}
802825
};
803826

804827
// Format and print text from child process
@@ -956,10 +979,13 @@ Interface.prototype.help = function() {
956979

957980
// Run script
958981
Interface.prototype.run = function() {
982+
var callback = arguments[0];
983+
959984
if (this.child) {
960985
this.error('App is already running... Try `restart` instead');
986+
callback && callback(true);
961987
} else {
962-
this.trySpawn();
988+
this.trySpawn(callback);
963989
}
964990
};
965991

@@ -1015,22 +1041,28 @@ Interface.prototype.list = function() {
10151041
var lineno = res.fromLine + i + 1;
10161042
if (lineno < from || lineno > to) continue;
10171043

1044+
var current = lineno == 1 + client.currentSourceLine,
1045+
breakpoint = client.breakpoints.some(function(bp) {
1046+
return bp.script === client.currentScript &&
1047+
bp.line == lineno;
1048+
});
1049+
10181050
if (lineno == 1) {
10191051
// The first line needs to have the module wrapper filtered out of
10201052
// it.
10211053
var wrapper = require('module').wrapper[0];
10221054
lines[i] = lines[i].slice(wrapper.length);
1055+
1056+
client.currentSourceColumn -= wrapper.length;
10231057
}
10241058

1025-
var current = lineno == 1 + client.currentSourceLine,
1026-
breakpoint = client.breakpoints.some(function(bp) {
1027-
return bp.script === client.currentScript &&
1028-
bp.line == lineno;
1029-
}),
1030-
line = current ?
1031-
SourceUnderline(lines[i], client.currentSourceColumn)
1032-
:
1033-
lines[i];
1059+
// Highlight executing statement
1060+
var line;
1061+
if (current) {
1062+
line = SourceUnderline(lines[i], client.currentSourceColumn)
1063+
} else {
1064+
line = lines[i];
1065+
}
10341066

10351067
self.print(leftPad(lineno, breakpoint && '*') + ' ' + line);
10361068
}
@@ -1412,7 +1444,7 @@ Interface.prototype.trySpawn = function(cb) {
14121444
}
14131445

14141446
setTimeout(function() {
1415-
process.stdout.write('connecting..');
1447+
self.print('connecting..', true);
14161448
attemptConnect();
14171449
}, 50);
14181450
};

0 commit comments

Comments
 (0)