Support Elixir expressions in Playground #564
Draft
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.
Implements #520.
This is a partially working implementation. There are probably unnoticed bugs and edge cases when it does work, but it works quite well in a lot of cases.
All attribute types are now editable. When Elixir expressions are expected, there is an Elixir-like icon visualizing that the input must be Elixir code. The icon goes red when the code is not valid and its title says what the error is. Textareas are used for these inputs, so that user can make them bigger.
The Elixir evaluation uses Dune under the hood. Therefore, the evaluation is relatively safe. However, there are two issues I noticed. The first one is small – structs cannot be constructed as their syntactic form is forbidden (don't know why). This can be fixed by implementing a custom Allowlist. The second issue is more important. To prevent atom exhaustion, atoms that don't already exist are translated to atoms like
: a__Dune_atom_1__
. Although not fatal, this considerably lowers the usability. Maybe we can say that the expression evaluation in playground should be enabled only on local machines without remote access and then just useCode.eval_string/1
…TODO: