-
Notifications
You must be signed in to change notification settings - Fork 8
Description
We either need to make sure that the single ExtendedPythonGenerator instance is being correctly used for multiple blockly workspaces, or we need to use multiple ExtendedPythonGenerator instances.
Right now there is a single ExtendedPythonGenerator instance, the extendedPythonGenerator variable that is declared in extended_python_generator.ts. But that generator is used to generate code for multiple blockly workspaces (for example, the workspace in the UI as well as headless blockly workspaces that we use for creating new modules, etc).
We have a method in ExtendedPythonGenerator called setCurrentModule that is called immediately before we call extendedPythonGenerator.workspaceToCode. This is done in the following places:
- In App.tsx, for generating the code that is displayed in the Python Code panel that is to the right of the visible Blockly Workspace.
- In editor/editor.ts, for generating the code that is saved to storage.
- In storage/common_storage.ts, for generating code when we create a new Project, Mechanism, or OpMode, or when we upload a Project.
We have another method in ExtendedPythonGenerator called getExportedBlocks that is called immediately after workspaceToCode after we call extendedPythonGenerator.workspaceToCode. This is done in the same places listed above, except not in App.tsx since it is not needed there.
In ExtendedPythonGenerator.init we collect information about the functions and variables that have been declared so we can produce the exported blocks.