ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Web playground with WASM

Open squiddy opened this issue 3 years ago • 7 comments

This MR provides a web playground for ruff. https://611ef32d.ruff-axw.pages.dev/

  • on-the-fly linting of code
  • configuration can be adjusted
  • persists config & source code in the URL for sharing (Example with code & config)

Technical details:

  • Split lib/main into wasm and native

Not all dependencies compile under the wasm target (or make sense to even include). I thought it best to make that explicit by splitting up the lib.rs between native and wasm. For main.rs I didn't find any other solution, apparantely one can not tell cargo to not build a binary under certain targets. The current main makes use of rayon and the current iterator wrapper breaks code check / clippy. I couldn't think of a good use case for WASM to have a direct entrypoint, so currently under wasm I provide a noop implementation.

  • Add web playground

Similar to @charliermarsh's original implementation this is based on vite & monaco-editor. The checks currently fail because I included a step to deploy the final result to cloudflare pages. Which obviously doesn't work due to the lack of secrets, and it also needs to be moved to some other main-only workflow.

  • Auto-generated options.ts

This powers the configuration in the playground. I'm keeping an eye on the current work on the JSON schema. Potentially that schema can replace the dev command I'm introducing here.


More can be done on the playground itself, but I'd appreciate some reviews, especially on the wasm side of things. Perhaps some of this can be merged and we iterate on the playground in future MRs.

squiddy avatar Dec 18 '22 16:12 squiddy

Nice, this would be cool to have. I published https://ruff.pages.dev/ at some point based on that code, it'd be nice to have that continuously deployed, more prominent, officially part of the codebase with WASM support, etc. Very supportive of this!

charliermarsh avatar Dec 19 '22 01:12 charliermarsh

Put together some configuration panel. Auto-generated from our options annotations. Not very user friendly, but wanted to see how easy passing in options from JS to rust is: very easy thanks to serde+wasm.

image

squiddy avatar Dec 19 '22 20:12 squiddy

this is awesome, testing it in a web app with codemirror and works great! thanks a lot @squiddy and @charliermarsh

didiercolens avatar Dec 20 '22 08:12 didiercolens

Marking as ready. I updated the MR description with some more details.

Sharing config & code via URL works now: Example

I thought that's nice to have, as it can make sharing bug reports nicer? E.g. for the false-positive RET504

squiddy avatar Dec 22 '22 14:12 squiddy

Awesome, pumped to review! Will try to get to it today but might be tomorrow.

(Permalinks is genius especially for bug reports.)

charliermarsh avatar Dec 22 '22 14:12 charliermarsh

It would also be cool to have permanent, versioned URLs somehow. I don't know exactly what that would look like, but for bug reports, it'd be nice if the URL that was shared was tied to a specific version of Ruff.

charliermarsh avatar Dec 24 '22 04:12 charliermarsh

It would also be cool to have permanent, versioned URLs somehow. I don't know exactly what that would look like, but for bug reports, it'd be nice if the URL that was shared was tied to a specific version of Ruff.

I was wondering whether it makes sense to decouple the playground from ruff itself. Have it provide the UI and all of that, but load the WASM files from somewhere depending on the version requested. If we were to include the available options inside the WASM, they would be pretty self-contained.

A link such as https://611ef32d.ruff-axw.pages.dev/?version=0.0.119#N4XwJBCWC2AOD2AnALgAngZwHQHcAWAhsgKYBuxiQA would then load the proper WASM file for 0.0.119.

squiddy avatar Dec 24 '22 06:12 squiddy