Purty IDE integration to format on save

Edit. Found:

  • vscode-purty extension
    • Can simply enable “Editor: Format On Save” in vscode settings, and ignore the below watchexec instructions
  • purty issue to consolidate vscode extensions

Original Post:

Does anyone use Purty to automatically format files upon save? What is your workflow?

Here’s one hackish option using watchexec:

  1. Create a format.sh script:
echo formatting $WATCHEXEC_WRITTEN_PATH
purty --write $WATCHEXEC_WRITTEN_PATH
  1. Run this command:
watchexec -w src -e purs -- ./format.sh

There may be some benign purty failures as the script is sometimes triggered again without setting the file path variable after purty overwrites.

A better long-term option is IDE integration as mentioned here:

Not sure if this will be more difficult than mimicking what was done with elm-format in elm-language-server. I assume the place to make this change is in purescript-language-server and the specific IDE extensions (e.g. vscode and atom).

Pinging maintainers @joneshf and @nwolverson for suggestions on how to proceed.

Somehow missed that there was already an extension for this:

vscode-purty

Then just enable “Editor: Format On Save” in vscode settings.

Edit:
Didn’t realize there was another discussion about integration with purty in the vscode extension repo.

Looked through these two repos already for purty discussions:
nwolverson/vscode-ide-purescript
nwolverson/purescript-language-server

But missed this one:
nwolverson/vscode-language-purescript