Fix Python Toolbox Filtering with Tutorial Template Code #10237
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, notpython-template
. I've gone with the more general check onlanguage
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:
This is it after:
I also confirmed the error no longer shows up when the toolbox is hidden.