Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
byorgey opened this issue Jun 17, 2024 · 6 comments
Closed

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

byorgey opened this issue Jun 17, 2024 · 6 comments
Labels
C-Project A larger project, more suitable for experienced contributors. L-Type inference The process of inferring the type of a Swarm expression. Z-Feature A new feature to be added to the game. Z-Research This issue requires inventing something new and/or studying research papers for clues. Z-User Experience This issue seeks to make the game more enjoyable to play.

Comments

@byorgey
Copy link
Member

byorgey commented Jun 17, 2024

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.

@byorgey byorgey added Z-User Experience This issue seeks to make the game more enjoyable to play. Z-Feature A new feature to be added to the game. C-Project A larger project, more suitable for experienced contributors. L-Type inference The process of inferring the type of a Swarm expression. Z-Research This issue requires inventing something new and/or studying research papers for clues. labels Jun 17, 2024
@xsebek
Copy link
Member

xsebek commented Jun 18, 2024

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

@byorgey
Copy link
Member Author

byorgey commented Jun 18, 2024

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
Copy link
Member

xsebek commented Jun 19, 2024

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
Copy link
Member Author

byorgey commented Jun 19, 2024

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
Copy link
Member Author

byorgey commented Jun 19, 2024

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)?

  • Edited to add: the first line of the error is not useful because it is always just something like 1:13: Type mismatch:.
  • Perhaps another idea would be to write a function to pretty-print error messages in a "compact" format, i.e. try to squeeze useful info about the error into a single line.

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.

@byorgey
Copy link
Member Author

byorgey commented Jan 1, 2025

I'm going to close this in favor of #2255 which I split out as a more specific issue. We did also get #1956 which helps a lot.

The other idea in this thread was to show some summary of the current error message in the UR corner of the REPL, but I don't think we can do that and #2255 at the same time. Showing the type of the currently focused thing seems more useful than showing the current error message, especially if the error is due to an incomplete/in progress input.

@byorgey byorgey closed this as completed Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Project A larger project, more suitable for experienced contributors. L-Type inference The process of inferring the type of a Swarm expression. Z-Feature A new feature to be added to the game. Z-Research This issue requires inventing something new and/or studying research papers for clues. Z-User Experience This issue seeks to make the game more enjoyable to play.
Projects
None yet
Development

No branches or pull requests

2 participants