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

Fix Python Toolbox Filtering with Tutorial Template Code #10237

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

thsparks
Copy link
Contributor

Fixes https://github.com/microsoft/pxt-minecraft/issues/2578

When a tutorial specifies python-template code (i.e. https://github.com/microsoft/pxt-minecraft/blob/master/docs/hour-of-code/2024/setdesign_python_activity2.md?plain=1#L8-L12) we were not parsing it correctly and ended up adding curly braces around the code. In some scenarios, the compiler could recover from the unexpected curly braces and still produce a few statements (seemed to happen when loops / indentation was present in the snippet), but in other cases, it was not able to recover. As a result, toolbox filtering wouldn't work and an error toast would appear. (Note that without this fix, the error toast still appears, even with the toolbox hidden.) Technically, even when the compiler did recover, some statements would be missing, so the filtering could theoretically be off there too.

The curly braces were being placed because we do it for typescript, and in the check to determine typescript/pyhon, we were only checking the snippet regex match for python directly, not python-template. I've gone with the more general check on language instead, in the hopes that it will be more resilient if we add more keywords in the future.

Tested by removing the flyoutOnly field and looking at the toolbox. This was it before:
image

This is it after:
image

I also confirmed the error no longer shows up when the toolbox is hidden.

Because we were only checking the snippet match for "python" and not "python-template", we were adding { } that are (I suppose) expected for typescript but break python parsing. I've gone with the more general language check here instead of just adding another case in the hopes that it will be more future-proof if we add any more possible keywords.
@thsparks thsparks requested a review from a team October 18, 2024 00:27
@abchatra abchatra merged commit 3bba3e1 into master Oct 18, 2024
7 checks passed
@abchatra abchatra deleted the thsparks/mc/fix_toolbox_filtering branch October 18, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants