VS Code format selection

Ok, classic beginner gripe, I know. In general I’m all for opinionated formatting—I don’t agree with everything about elm-format but it’s so nice to be able to switch off that part of my brain and leave it to do the work; and for there to be a single recognisable format community-wide. But I tried enabling format on save for ReScript for a day and I can just tell we’re not going to get along; it’s actively harming readability and usability.

It looks like the issues have mostly been discussed before (especially forced single-line structures). I don’t want to come in on day 3 of using a new language and kick up a fuss. Instead I’m turning off format on save, and I’ll try to keep my code formatted close to the standard, save for multiline flexibility and a couple of other tiny niggles.

So ideally I’d like to format any parts of a file where the formatter does a reasonable job, and/or use it to discover what the standard formatting for a given structure is. But format selection doesn’t seem to be working in VS Code. Neither is eg. format on save mode set to just “modifications”. So I’m wondering if the ReScript formatter only supports whole-file formatting? Is there a way to get selective formatting working?

Alternatively, I don’t suppose there are third-party alternative formatters available? I realise that the existence of such tools would somewhat undermine the aims of a single opinionated formatter, but for me the usability/readability costs of turning on the formatter outweigh the costs of even manual formatting.

As for the feature itself, formatting a selection, I think it should be pretty easy for us to implement. Please file an issue on the repo. You’re correct that we only support full file formatting for now.

For formatting etc, please make sure you contribute your thoughts to the various discussions that has been ongoing about the formatting, even if just reiterating points already there, and even if you’re early into using the language.

While a goal is to have opinionated formatting to an as large extent as possible, I think exactly what those opinions are aren’t necessarily set in stone, at least not for all cases. And then of course, like you say, there’s always going to be some things that annoy some people that others like, and vice versa. Everyone’s never going to be fully happy :smiley:

4 Likes

Thanks. Ok I created an issue on the VS Code extension (though it might at root be an issue with the compiler itself?) https://github.com/rescript-lang/rescript-vscode/issues/542

I’d be happy to contribute my thoughts to discussions about formatting. Where would be best to do that?