Visual Studio Code will not react if the user presses Shift + Alt + F. On the contrary, Visual Studio F# Power Tools support code formatting.
Formatting in VFPT is implemented using Fantomas. To enable source code formatting in vscode a DocumentFormattingEditProvider would need to be implemented.
As Fantomas cannot be used inside of this repo the formatting functionality would need to be implemented as a part of FsAutoComplete with commands on this side to call the formatting service and apply the set of text edits it receives back to the editor buffer.
Feel free to submit a PR
It doesn't look very complex, I could try adding that.
To summarize:
You can use the VFPT implementation as a reference
Expect an increase in issues when Fantomas starts breaking people's code and when they complain about the limitations of the settings and options for configuration
formatting needs to operate on dirty buffers
Do you mean on the content of the buffer(text editor) which might not be saved to disk yet, so I need to send the whole text to the endpoint for formatting?
yup
In IntelliJ, I think it blocks formatting (for Java at least) if there is a compiler error in the current buffer. If that's possible here, it would hopefully prevent a lot of "fantomas broke my code".
This pull request has added an FSAC endpoint. What else needs to be done?
This would be great to have, is this something that is still doable?
I guess, but I don't get any response from the developers. @Krzysztof-Cieslak?
There are merge conflicts there, I bet they won't take a look if it is not fixed first.
hey guys, how is this going?
No progress?
I literally don't know. They said that Fantomas would be integrated to FCS, yet the actual Fantomas has an issue with outdated libraries. I submitted a PR to fix it, and got no response.
There is no plan to add F# Formatting (Fantomas) support in its current state due to quality problems of the formater. Some activity discussing adding it to VF# and FCS is happening here - https://github.com/Microsoft/visualfsharp/pull/3542, please check @dsyme's comments about existing Fantomas issues.
I just wrote my own source code formatter, may be it can be used for this issue.
if there is a way, pleeeeeeeeeease make it happen... ;)
Nowadays this is a must ;)
Hey @Krzysztof-Cieslak. hypothetically 馃構 what would need to be done for this?
Fantomas is in a slightly better state now and I might want to try and integrate it.
I would assume there are two components here:
Could you provide me with some pointers?
Because we use LSP there's one thing that must happen - we must implement it on the server side, "press format code in VSCode" part we get for free ;-).
We need to implement couple of overrides (https://github.com/fsharp/FsAutoComplete/blob/master/src/LanguageServerProtocol/LanguageServerProtocol.fs#L2023-L2035) in the FsharpLspServer class (https://github.com/fsharp/FsAutoComplete/blob/master/src/FsAutoComplete/FsAutoComplete.Lsp.fs#L46) in FSAC and inform client that server has the formatting capabilities (change what we return here - https://github.com/fsharp/FsAutoComplete/blob/master/src/FsAutoComplete/FsAutoComplete.Lsp.fs#L337-L369)
Since the problem is only related to server side, let's move any further discussion to FSAC repo.
Since Fantomas integration has been merged into FsAutoComplete, is there anything else to do from the Ionide side?
No, this should be closed
Most helpful comment
if there is a way, pleeeeeeeeeease make it happen... ;)
Nowadays this is a must ;)