ionide / ionide-vscode-fsharp

VS Code plugin for F# development
http://ionide.io
MIT License
865 stars 279 forks source link

Support `Format Selection` #1499

Closed kevingentile closed 2 years ago

kevingentile commented 3 years ago

Describe the bug**

Selecting a block of code and hot-keying "Format Selection" produces no behavior.

Steps to reproduce

  1. Write out a block of code
  2. Highlight block
  3. Format selection ( Windows ctrl +k ctrl + f)

Expected behaviour

Block of code is formatted

Machine info

Additional context

"Format document" works as expected. The "Format Selection" hotkeys work for other languages.

open-collective-bot[bot] commented 3 years ago

Hey @kevingentile :wave:,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our OpenCollective and consider backing us.

https://opencollective.com/ionide

PS.: We offer backer support for all backers. Don't forget to add backer label when you start backing us :smile:

Krzysztof-Cieslak commented 2 years ago

Hey @nojaf - I see that FantomasService expose FormatSelectionAsync, do you think it is ready for prime time? ;-)

nojaf commented 2 years ago

Well, maybe 😸. I've done a bit of revamping of how selection works in Fantomas and the current Fantomas.Client does expose FormatSelectionAsync.

All LSP ranges should be converted to FCS ranges (well https://github.com/fsprojects/fantomas/blob/452064c6e05acd2eaa71520ea006c45cc0455783/src/Fantomas.Client/Contracts.fs#L48-L60, which have the same semantics).

If the selection worked (the scenarios are limited to https://github.com/fsprojects/fantomas/blob/master/docs-old/Documentation.md#format-selection), you get a SelectedRange to know what you really need to replace.(https://github.com/fsprojects/fantomas/blob/452064c6e05acd2eaa71520ea006c45cc0455783/src/Fantomas.Client/Contracts.fs#L69).

The best of luck I'd say.

Krzysztof-Cieslak commented 2 years ago

This has been implemented in https://github.com/fsharp/FsAutoComplete/pull/969 and will be available in the next Ionide release.