source-academy / frontend

Frontend of Source Academy, an online experiential environment for computational thinking (React, Redux, Saga, Blueprint)
https://sourceacademy.org
Apache License 2.0
103 stars 168 forks source link

Correct "show type" feature in Source §x Typed #2421

Open martin-henz opened 1 year ago

martin-henz commented 1 year ago

Currently, the deprecated type inference feature is used for the show type shortcut:

Screen Shot 2023-04-04 at 11 01 23 AM

(activate the feature with control-shift-m: https://github.com/source-academy/frontend/wiki/Source-Academy-Keyboard-Shortcuts)

We should disable this for the untyped Source variants, and switch this to the declared type of names (or any if no type is declared) for the typed variants of Source.

martin-henz commented 1 year ago

@zhaojj2209 any comments? Are the types available in the AST?

zhaojj2209 commented 1 year ago

We should be able to retrieve the types from the type environment if we are able to pause execution at the exact line. Perhaps we can look into breakpoint support? E.g. Insert a debugger statement at the line where we want to show the type, then modify the type checking function to return the type environment at the point of encountering the debugger statement.

martin-henz commented 1 year ago

We should be able to retrieve the types from the type environment if we are able to pause execution at the exact line. Perhaps we can look into breakpoint support? E.g. Insert a debugger statement at the line where we want to show the type, then modify the type checking function to return the type environment at the point of encountering the debugger statement.

Why should we do this at runtime? We can (re)run the type checker when the user wants a type, and look for the right variable (using line and column info). [Would be nice to find the type of expressions, too.]

zhaojj2209 commented 1 year ago

Apologies for the confusion, yes we should do this at compile time.

The type checker recurses through the AST to get the type of every node. We can perhaps modify the function to take in the location of a node and "save" the type for that particular node when typechecking. This way, we would be able to get the type of any node.

martin-henz commented 7 months ago

Update: The hotkey is still documented, but disabled for all Source versions, including Source Typed.