swarm-game / swarm

Resource gathering + programming game
Other
820 stars 51 forks source link

More help from the typechecker in constructing valid REPL inputs #1955

Open byorgey opened 1 week ago

byorgey commented 1 week ago

Is your feature request related to a problem? Please describe. It's annoying when you are in the middle of typing something like

build {myComplexFunction ... }

and you need to fill in the ..., but you can't remember exactly what the type of myComplexFunction is, but Swarm is no help because the entire thing does not typecheck so it is just highlighted in red.

Describe the solution you'd like I am not sure exactly what a solution would look like. Just brainstorming some ideas here.

What if there were key shortcuts that let you move the "current focus" inward + outward. For example if you have already typed build {myComplexFunction } with the cursor right after myComplexFunction you could hit the "focus inward" key and it would switch to focusing on just the part inside the {} (which could be indicated by different color highlighting). It could then show you the type that needs to go in the hole (Cmd Unit) and the type of what you currently have (Some -> Complex -> Function -> Type -> Cmd Unit). Maybe hitting "focus inward" one more time would switch to focusing just on the first argument to myComplexFunction.

Describe alternatives you've considered A simpler alternative would be the ability to have "typed holes" where you can put something like _ or ? in place of missing subterms and have the system report their types to you. However, this would be kind of annoying (if you don't remember the type of myComplexFunction you might not even remember how many arguments it needs, and even if you did it would be annoying to have to type a bunch of question marks), and it might be difficult to tell the question marks apart.

xsebek commented 1 week ago

@byorgey I think we could improve a little even by highlighting only ContextualTypeErr source location.

byorgey commented 1 week ago

Yes, great idea. I would still love to have what is described in this issue (better error highlighting still does not help you know how to fix the error, or what should go in a hole) but that would be much better than the status quo.

xsebek commented 1 week ago

How, about showing the type of function the cursor is on?

Also I think it would be helpful to see the current error text. The only issue is finding space for it.

byorgey commented 1 week ago

How, about showing the type of function the cursor is on?

Yes, that would make sense I think. We should already have some code in the LSP server which computes this, perhaps we could abstract it out into swarm-lang.

byorgey commented 1 week ago

Also I think it would be helpful to see the current error text. The only issue is finding space for it.

How about just showing the first line of the current error text, in the same space where the type is usually shown (i.e. the top right corner of the REPL panel)?

If you want to see the whole error message you can always hit Enter, it will be printed in the REPL, then you can hit Up and continue editing the input.