microsoft / microsoft/pxt

Allow `pxt.json` to append to the `runtime.functionOptions.extraFunctionEditorTypes` array

Open
#10,830 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
641
Avg merge
12h 4m
Merged PRs (30d)
57

Description

Is your feature request related to a problem? Please describe.

I'm trying to teach good problem decomposition using functions and classes. As a scaffolding step I want to provide the class definitions for students, as well as template code, and have students populate a function with their implementation to explore possible solutions.

Unfortunately at this stage it is not possible to have blockly functions take custom classes as argument types.

Describe the solution you'd like

In the same way that pxt-microbit/pxtarget.json is able to populate the runtime.functionOptions.extraFunctionEditorTypes field to add sprites and images, I would like my own projects/extensions to be able to add a field to the pxt.json file to extend this extraFunctionEditorTypes array to make my own custom classes available as function arguments.

Describe alternatives you've considered

It is possible to 'kludge' around this by always passing an array of 1 element of the custom type, but this is clumsy and not the correct way to use a type-checked language like typescript. It could also potentially lead to confusion if any students "peek under the hood".

I am also concerned that due to type inference mechanisms around arrays a student may get into a situation where, due to mismatched types (an accidental placement of a block in the wrong context), the student becomes confused and unable to proceed with the activity.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare pxt-microbit/pxtarget.json with the pxt.json configuration handling for runtime.functionOptions.extraFunctionEditorTypes. Trace how that setting reaches Blockly function argument editors. Done means a project or extension can append custom function editor types through pxt.json, making custom classes available as function argument types.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.