rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

Feature: format selection

Open baffalop opened this issue 3 years ago • 2 comments

I'm new to ReScript and I've been trying the VS Code extension with Format on Save enabled. However, I'd like to manually control formatting with the Format Selection command (more on my reasons here). But the extension's formatter only seems to support whole file formatting. Neither Format Selection, nor setting the Format on Save Mode to "modifications", seem to do anything.

This would be an important feature for me since I don't think I can carry on with Format on Save enabled (I don't like some of the formatter's behaviour) but I'd like to stick to standard formatting as much as possible so it would help a lot with that.

I don't know if this is an issue with the extension or with the formatter itself being unable to handle partial content, but I thought I'd create the issue for the component where I experience the problem.

baffalop avatar Aug 02 '22 16:08 baffalop

Curious, how does formatting like this typically work? Is it typically resilient to selecting a syntactically invalid ranges?

zth avatar Aug 02 '22 17:08 zth

Hmm, good question. I'd imagine so. In my experience, formatting tools simply tend to terminate (ie. return the remaining contents unchanged) at the point where they encounter a syntax error. Is that not how the ReScript formatter behaves? Would that be enough to make it resilient?

I suppose the other thing to consider is if it's provided a selection which isn't entirely linewise (say a block together with its enclosing braces which is itself part of a function definition), but I'd perhaps count that as misuse and accept any weird formatting that results.

baffalop avatar Aug 02 '22 17:08 baffalop