crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.43k stars 1.62k forks source link

Playground file opening/saving #3531

Open refi64 opened 7 years ago

refi64 commented 7 years ago

Right now, no one's trying to host the playground online or anything. What if it came with a file browser, so you could actually use it to open up files and also save them? It would all be done server-side.

Obviously, if someone's stupid enough to leave it running on a public port, then that's a major security risk. Then again, if they're stupid enough to leave it running on a public port, they're probably screwed anyway (dirtycow, anybody?).

bcardiff commented 7 years ago

When the playground was built there were some discussion about how much of an editor for the full development cycle it should be.

The big scenario would requite to handle all this:

  1. That you need to select a main file to compile
  2. Instrument all the open files. So if the user changes the focused file it can see how the flow worked from the main file to it.
  3. Make the compiler pluggable to determine the actual code of the dependencies. So if the file is open then the instrumented version of the code will be loaded.

A small scenario will be to add an option to the command

$ crystal play [options] [file]

So the initial code will be autosaved to the file again. Maybe something like: --editor -w -s In autosaving sessions, maybe, the localstore should be disabled.

An intermediate scenario would be allow the user to navigate local files and load them as the current code. Without the context of many open files. Which is done in the workbooks but without the autosaving.

$ tree playground
playground
└── foo.cr
$ crystal play
# open http://localhost:8080/workbook

Which scenario where you thinking about?

marksiemers commented 6 years ago

Would it be possible to add an option (or default) for the workbook to load files recursively?

The code here: https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/tools/playground/server.cr#L290

private def files
  Dir["playground/*.{md,html,cr}"]
end

Would just need to become:

private def files
  if recursive_workbook
    Dir["playground/**/*.{md,html,cr}"]
  else
    Dir["playground/*.{md,html,cr}"]
  end
end

A more advanced solution would create the file tree in the web browser also.

One big feature of this, you can create a symlink ./playground -> ./src and easily load any of your source files in the playground - browsing through the workbook.

straight-shoota commented 6 years ago

I think recursively loading files in subdirectories and mapping them to the appropriate paths should be the default.

This would be handy for organizing more extensive workbook collections. #4462 comes to mind...