walnuthq / cairovm.codes

Source code for cairovm.codes — a web app to compile Cairo programs into Sierra and CASM with step-through execution capabilities.
https://cairovm.codes
MIT License
30 stars 24 forks source link

Cairo code formatter #37

Open mazurroman opened 7 months ago

mazurroman commented 7 months ago

Let's add a code-format button next to the permalink button. Clicking the button should reformat the Cairo code so that users don't need to manually set indentation.

For the icon, I suggest to use one of these three icons from https://remixicon.com/ : code-line, code-s-line, code-s-slash-line but we're open to hear other icon suggestions

remybar commented 7 months ago

Hi @mazurroman 👋

Do you already have an idea of how to format Cairo code from the front-end ?

I've investigated a bit to see how to do that but I didn't find any quick solution:

Then, if you have an idea about how this code formatting should be implemented, I'm available to do it ;-)

mazurroman commented 7 months ago

Hi @remybar thank you for listing all available options, it's very clear and helpful. Let's wait for @barabanovro to suggest which option is the best.

barabanovro commented 7 months ago

@mazurroman I would suggest using the cairo-lang-formatter crate that Rémy mentioned and compiling it to WASM so that it can be used on the frontend. It is going to require some work to make the crate compilable to WASM and probably will require forking it.

mazurroman commented 7 months ago

@barabanovro I am not a fan of forks and we should avoid them wherever possible. Everything in Starknet is under heavy development. Forking cairo-lang-formatter means we would need to manage our fork which will create new responsibilities and commitments on us.

I like the idea to use WASM here. @barabanovro can you create an issue on the cairo-lang-formatter project to make it WASM compatible and link the issue here as a blocker. Once that issue is done we can resume the work.

barabanovro commented 7 months ago

This issue is blocked by cryptonerdcn/wasm-cairo#15

mazurroman commented 7 months ago

Note: cryptonerdcn (owner of the wasm-cairo repository) confirmed that the https://github.com/cryptonerdcn/wasm-cairo/issues/15 issue is eligible for rewards on OnlyDust