jcartledge / sublime-worksheet

An inline REPL for JavaScript, PHP, Ruby & more in Sublime Text 2 and 3
MIT License
332 stars 18 forks source link

Stops evaluating on return statement #20

Closed sindresorhus closed 11 years ago

sindresorhus commented 11 years ago

This JS code stop evaluating on the return statement.

function foo() {
    return 'bar';
// > Execution timed out.
}

console.log(foo());
jcartledge commented 11 years ago

Ouch. I haven't seen that in my own testing, and don't see it with your example:

function foo() {
    return 'bar';
}
// > undefined

console.log(foo());
// > bar
// > undefined

Can you tell me the output of node -v on your system?

(BTW thanks for reporting this!)

sindresorhus commented 11 years ago

v0.10.11

sindresorhus commented 11 years ago

Works fine in the Node REPL

danharper commented 11 years ago

Same here:

var doubleIt = function(num) {
    return num * 2;
// > Execution timed out.
}

doubleIt(2);

Node v0.10.2

jcartledge commented 11 years ago

Thanks. I really want to get to the bottom of this, but at present I can't reproduce it. Anything you can provide which will help me to get this result (OS, ST version, ???) would be greatly appreciated.

It looks like pexpect is hanging waiting for a prompt before it sends the next line to node. The relevant selection of the config is:

"JavaScript": {
    "cmd": "node -e \"require('repl').start('node> ')\"",
    "prompt": ["node> ", "\\.\\.+ "]
}

So we run node with a custom prompt then look for that prompt, or a run of dots (which is what is shown when inside a {} block.)

What prompt do you see in the node REPL when you are inside the body of the function?

danharper commented 11 years ago

Weirdly, @sindresorhus's example works for me, though:

function foo() {
    return 'bar';
}
// > undefined

console.log(foo());
// > bar
// > undefined

OSX 10.8.3 Sublime 2.0.1 build 2217

danharper commented 11 years ago

Wait. It's all working fine now? I didn't change anything. Same document, just re-pasted what I copied into here.

jcartledge commented 11 years ago

Thanks Dan. That's nuts. I'm glad to hear it's working now, but it sounds like there's definitely a bug here. Please post if you find anything else.

danharper commented 11 years ago

Idk, it's timed out again. In the node repl, it looks like this:

> var doubleIt = function(num) {
... return num * 2;
... }
undefined
> doubleIt(2);
4
>
lpand commented 11 years ago

I don't know if this is related to this bug –if not i apologize– but, when i try to run any javascript code line i get this error inside the sublime interpreter:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./worksheet.py", line 101, in run
  File "./worksheet.py", line 19, in run
  File "./repl/repl.py", line 8, in get_repl
  File "./repl/repl.py", line 42, in __init__
  File "./repl/pexpect.py", line 429, in __init__
  File "./repl/pexpect.py", line 516, in _spawn
repl.pexpect.ExceptionPexpect: The command was not found or was not executable: node.

And obviously node works inside the terminal.

With Ruby it works.

I have OSX 10.8.4 and ST 2.0.1, build 2217. Thanks,

Luca

ghost commented 11 years ago

I have the same issue.

The NodeEval plugin works as expected, returning 7.

var x = 5;
// > undefined

function add_two(num) {
    return (num + 2);
// > Execution timed out.
}

add_two(x);

This issue aside, awesome plugin - thanks for your work!

jcartledge commented 11 years ago

@CarettaCaretta - that sounds like a different bug. Can you please open a new issue for it? Thanks very much.

jcartledge commented 11 years ago

OK I got it: it's tabs. The workaround is to indent with spaces but I know noone is going to be happy with that, so I guess I'll substitute them before sending to the REPL. Thanks to everyone who reported this; I had no idea.

jcartledge commented 11 years ago

There's a new tag - 0.7.2 - which should fix this. Not sure how long that will take to flow through to Package Control.

danharper commented 11 years ago

Bizarre. Thanks for the update.