Embedded Go Playground
Problem to solve
Often when going through documentation/wikis/blogs there is a need to run some code (Code Playground) for experimentation/learning purposes. When a documentation/wiki/blog doesn't have a way to run code it significantly slows down the learning process (in some cases), and makes it more difficult to understand what is being read.
Quoted from #22632, as this is related to/a specific case of that request.
Intended users
Further details
Being able to execute code snippets would be a very powerful feature for GitLab. It would tie in with existing code execution efforts for the WebIDE. It could facilitate powerful documentation. It could be used in issues to demonstrate bugs.
The Go playground supports multiple files separated by --- path/to/file.ext ---\n
, for example.
The Go playground runs code in a special sandbox with simulated time, filesystem, and network (see this blog post for functional details). The compilation result includes (stdout/err) messages and the simulated delay between each message. The front end replays these with appropriate delays.
Proposal
At first, I am suggesting something like the existing support for PlantUML: a markdown filter that recognizes a custom language (e.g. goplay
) and an API endpoint that uses https://play.golang.org to compile and execute Go.
I've implemented a quick and dirty prototype:
This will obviously require UX development. It should probably also have a link to open play.golang.org
. Besides /compile
, the playground also has /fmt
for formatting code and /share
for generating shareable links. The playground source is available on github and GitLab should support setting up a local instance of the playground or using play.golang.org
.
In the future, I'm imagining live code editors with play support, which would be especially useful in wikis or markdown files in the repo, for documentation and learning.
Permissions and Security
Possibly require the user to be logged in, to avoid DOS attacks.
Documentation
Add a description of the user-facing feature to user/markdown.md and a new page to administration/integration to detail how to configure and administrate it.
Availability & Testing
What does success look like, and how can we measure that?
Code blocks marked with the language goplay
render with a play button. When the button is pressed, the code is executed and results are shown (below the code).
What is the type of buyer?
Individual Contributors for sharing code, Manager/Director for documentation and improved learning.
Is this a cross-stage feature?
The link in the template to 'cross stage features' is broken, so I'm not sure. Because this involves backend and frontend work, yes?