Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Solve the halting problem #40

Closed
Rich-Harris opened this issue Aug 23, 2019 · 10 comments · Fixed by sveltejs/svelte#3887 or #58
Closed

Solve the halting problem #40

Rich-Harris opened this issue Aug 23, 2019 · 10 comments · Fixed by sveltejs/svelte#3887 or #58

Comments

@Rich-Harris
Copy link
Member

it's really annoying when you're in the middle of typing a for loop...

for (let i = 0; i < things.length; <cursor>)

...and the code starts running before you have a chance to write i += 1. Similarly if you're trying to write this...

while (true) {
  // some code...
  if (someConditionIsMet()) break;
}

...you will get as far as while (true) {, it will add the closing }, and you're screwed.

Maybe not the easiest thing to fix, and certainly not in a general way, but I wonder if there's something that can be done to handle common cases. Like, idk, not running the code if the cursor is currently inside a loop?

@ghost
Copy link

ghost commented Aug 23, 2019

Maybe a mode (like JSFiddle) where it doesn't re-parse / execute until you tell it to?

@mallsoft
Copy link

Maybe a floating button inline that lets you "merge" the last written code so it doesn't evaluate anything before you are done typing things?
This could be expanded upon to mean all code and not just loops.
If it's really that important to get that super instant feedback, could a shortcut for the "merging" functionality suffice?

@Rich-Harris
Copy link
Member Author

I think a 'run when i say' mode would be a good addition, yeah. I still kinda like defaulting to instant feedback, I find I work much quicker that way. Maybe the best UX is somewhere in between the two extremes

@pngwn
Copy link
Member

pngwn commented Aug 26, 2019

If we decide to disable running when the cursor is inside the loop what if you make a genuine mistake but don't move your cursor? Then you have no feedback at all and you might not know what you've done wrong immediately. Maybe we can provide a REPL specific error to provide the required feedback.

@ghost
Copy link

ghost commented Aug 26, 2019

We could also expose the currently hard-coded CodeMirror options for auto brackets and such, but won't help in the case of the for loop example. I know I'd like to have tab sizes a wee bit bigger than 2 spaces personally and auto-quoting drives me nuts :)

@dhonx
Copy link

dhonx commented Aug 28, 2019

@Rich-Harris , Maybe this could solve ? See 👉 JSBin/loop-protect

@Conduitry
Copy link
Member

That library is implemented as a Babel transform, so we wouldn't want to use it as is. But it might be an interesting idea to steal and implement as a preprocessor that walks the AST and looks for these loops.

@dhonx
Copy link

dhonx commented Aug 28, 2019

Ya... exactly...

that is what i mean... i read the source code.. its too complex for me,, maybe we can simplify that... are you working on it now @Conduitry ??

@weepy
Copy link

weepy commented Oct 16, 2019

Could you just prevent instant reload if the cursor is within a loop parentheses?

@mustafa0x
Copy link

mustafa0x commented Nov 3, 2019

#55 (handle_change should be debounced) could help with this — you would just have to keep typing within the debounce timeout (200ms probably makes sense).

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

Successfully merging a pull request may close this issue.

7 participants