Skip to content

Commit

Permalink
Format selection (#2272)
Browse files Browse the repository at this point in the history
* Remove unused functions in Trivia.fs.

* Add first proof of concept of FormatSelection.

* Use mkSynExprNode for toplevel SynExpr nodes.

* WIP tree shape

* Refactor TriviaNodeAssigner to tree structure.

* Find node in selection using tree format.

* Remove FileIndex check for rangeContainsRange.

* Consider selection range when collecting trivia.

* Slowly restoring trivia again via tree structure.

* Fix some more unit tests.

* Remove SynComponentInfo_ as actual parent node.

* Remove SynValData_ as actual parent node.

* Use full range for SynField.

* Run the final continuation for Sequentials.

* Combined get/set members in a single node.

* Include leading comments in the file range.

* Collect all comments on single line.

* Use full range for ModuleOrNamespace.

* Print trivia for SynExpr.Const.

* Add trivia after last child if nothing fits before.

* Restore block comment in PostfixList.

* Don't collect blank lines from zero range source code.

* Print trivia after infix app in NewlineInfixApp.

* Stay within the boundaries of the source text.

* Remove old test.

* Correct full range of SynExprRecordField.

* Use SynExpr_Const for synExprToFsAstType.

* Include conditional directives in ParsedInput range.

* Remove SynTypeDefnRepr_ObjectModel as node.

* Use correct SynModuleOrNamespaceSig_ kinds.

* Print trivia for AnonRecordFieldName.

* Print trivia before anon record field at right column.

* Use parsedData from SynExpr.Lambda in AstTransformer.fs.

* Print after trivia for same infix application.

* Combine NewlineInfixApps and SameInfixApps under a single parent node.

* Add newline when attribute contains comment.

* Print trivia for SynPat.Or.

* Add children of valSig node to SynMemberSig.Member.

* Remove duplicate SynType_Paren.

* Duplicate with/and keyword in SynMemberDefn.Member.

* Take the smallest possible trivia node for comment after source code.

* Print leading newlines when formatting a selection.

* Revisit trivia type names.

* Clean up Trivia.fs.

* Remove SynTypeDefnSigRepr_ObjectModel type.

* Use last node inside SynExpr.App to assign trivia after to.

* Update to SynAccess range commit from fork.

* Print trivia for keyword in union and record declarations.

* Take the smallest node after.

* Update compiler to "Add arrow to SynType.Fun trivia".

* Add trivia after arrow in SynType.Fun.
Extend visitLastChildNode.

* Add regression tests from dotnet/fsharp.

* Trim the selection to the first code positions. Try and format that exact trimmed selection.

* Format certain selections in signature files.

* Correct typos and introduce signature file for Selection.fs

* Reestablish format selection in Daemon.

* Don't return option for FormatSelection API, try and be consistent with the FormatDocument.

* Add documentation for selection api.

* Clean up.
  • Loading branch information
nojaf committed Jun 26, 2022
1 parent 3949f8f commit 4d98e26
Show file tree
Hide file tree
Showing 46 changed files with 3,745 additions and 2,588 deletions.
20 changes: 19 additions & 1 deletion docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,25 @@ Note that Fantomas only searches for a `.fantomasignore` file in or above its cu

## Using the API

See [CodeFormatter.fsi](../src/Fantomas/CodeFormatter.fsi) to view the public API of Fantomas.
See [CodeFormatter.fsi](../src/Fantomas.Core/CodeFormatter.fsi) to view the public API of Fantomas.

### Format selection

Fantomas provides limited support for formatting a selection of code in a file, using the `CodeFormatter.FormatSelectionAsync` function.
This is a very challenging domain, so not every scenario is covered.
Fantomas is able to format:
- Top-level declarations like [SynModuleDecl](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synmoduledecl.html) and [SynModuleSigDecl](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synmodulesigdecl.html).
- Expressions like [SynExpr](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synexpr.html)
- 'val' definitions like [SynValSig](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synvalsig.html)

The selection can have leading or trailing spaces but an exact selection is recommended.
Invalid selections where no matching AST node is found will result in an exception.
The return value of the function is the formatted code and the range of the formatted AST node.
If the input selection range contained whitespaces, the result selection will contain the exact range of the formatted AST node.

Please consider contributing to this feature if you encounter any issues.

```fsharp
## A git pre-commit hook sample
Expand Down
178 changes: 89 additions & 89 deletions paket.dependencies

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -171,96 +171,96 @@ NUGET
GITHUB
remote: fsprojects/fantomas
src/Fantomas/CodePrinter.fs (829faa6ba834f99afed9b4434b3a1680536474b2)
remote: dotnet/fsharp
src/Compiler/AbstractIL/il.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/il.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/ilascii.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/ilascii.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/illex.fsl (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/illex.fsl (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/ilpars.fsy (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/ilpars.fsy (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/ilx.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/AbstractIL/ilx.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/DiagnosticOptions.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/DiagnosticOptions.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/DiagnosticsLogger.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/DiagnosticsLogger.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/LanguageFeatures.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/LanguageFeatures.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/Logger.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/Logger.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/prim-lexing.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/prim-lexing.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/prim-parsing.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/prim-parsing.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/TextLayoutRender.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/TextLayoutRender.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Facilities/UtilsStrings.txt (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/FSComp.txt (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/FSStrings.resx (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Interactive/FSIstrings.txt (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/lex.fsl (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/lex.fsl (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/pars.fsy (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/pars.fsy (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/pplex.fsl (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/pplex.fsl (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/pppars.fsy (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/pppars.fsy (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/LexFilter.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/LexFilter.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/LexHelpers.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/LexHelpers.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/ParseHelpers.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/ParseHelpers.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/PrettyNaming.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/PrettyNaming.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/SyntaxTree.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/SyntaxTree.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/SyntaxTreeOps.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/SyntaxTreeOps.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/SyntaxTrivia.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/SyntaxTrivia.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/UnicodeLexing.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/UnicodeLexing.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/XmlDoc.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/SyntaxTree/XmlDoc.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/FileSystem.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/FileSystem.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/HashMultiMap.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/HashMultiMap.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/ildiag.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/ildiag.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/illib.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/illib.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/InternalCollections.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/InternalCollections.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/lib.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/lib.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/PathMap.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/PathMap.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/QueueList.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/QueueList.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/range.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/range.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/rational.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/rational.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/ResizeArray.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/ResizeArray.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/RidHelpers.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/sformat.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/sformat.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/sr.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/sr.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/TaggedCollections.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/TaggedCollections.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/XmlAdapters.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/XmlAdapters.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/zmap.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/zmap.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/zset.fs (b822e2793bd6387c40cfd5b25d604e002a253257)
src/Compiler/Utilities/zset.fsi (b822e2793bd6387c40cfd5b25d604e002a253257)
remote: nojaf/fsharp
src/Compiler/AbstractIL/il.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/il.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/ilascii.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/ilascii.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/illex.fsl (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/illex.fsl (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/ilpars.fsy (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/ilpars.fsy (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/ilx.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/AbstractIL/ilx.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/DiagnosticOptions.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/DiagnosticOptions.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/DiagnosticsLogger.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/DiagnosticsLogger.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/LanguageFeatures.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/LanguageFeatures.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/Logger.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/Logger.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/prim-lexing.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/prim-lexing.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/prim-parsing.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/prim-parsing.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/TextLayoutRender.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/TextLayoutRender.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Facilities/UtilsStrings.txt (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/FSComp.txt (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/FSStrings.resx (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Interactive/FSIstrings.txt (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/lex.fsl (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/lex.fsl (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/pars.fsy (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/pars.fsy (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/pplex.fsl (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/pplex.fsl (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/pppars.fsy (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/pppars.fsy (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/LexFilter.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/LexFilter.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/LexHelpers.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/LexHelpers.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/ParseHelpers.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/ParseHelpers.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/PrettyNaming.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/PrettyNaming.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/SyntaxTree.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/SyntaxTree.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/SyntaxTreeOps.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/SyntaxTreeOps.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/SyntaxTrivia.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/SyntaxTrivia.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/UnicodeLexing.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/UnicodeLexing.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/XmlDoc.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/SyntaxTree/XmlDoc.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/FileSystem.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/FileSystem.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/HashMultiMap.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/HashMultiMap.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/ildiag.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/ildiag.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/illib.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/illib.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/InternalCollections.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/InternalCollections.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/lib.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/lib.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/PathMap.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/PathMap.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/QueueList.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/QueueList.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/range.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/range.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/rational.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/rational.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/ResizeArray.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/ResizeArray.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/RidHelpers.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/sformat.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/sformat.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/sr.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/sr.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/TaggedCollections.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/TaggedCollections.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/XmlAdapters.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/XmlAdapters.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/zmap.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/zmap.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/zset.fs (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
src/Compiler/Utilities/zset.fsi (0f1a901cb7fd93dd32f051ceb364247cb9218fc9)
GROUP build
STORAGE: NONE
NUGET
Expand Down
5 changes: 5 additions & 0 deletions src/Fantomas.Client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This is the changelog for the Fantomas.Client package specifically. It's distinct from that of the overall libraries and command-line tool.

## [Unreleased]

### Changed
* Add `SelectedRange` to `FantomasResponse`.

## 0.5.4 - 2022-05-06

* FSharp.Core 5.0.1 or higher. [#2227](https://github.com/fsprojects/fantomas/pull/2227)
Expand Down
16 changes: 12 additions & 4 deletions src/Fantomas.Client/Contracts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ type FormatDocumentRequest =
Config: IReadOnlyDictionary<string, string> option
}

type FantomasResponse =
{ Code: int
FilePath: string
Content: string option }
member this.IsSignatureFile = this.FilePath.EndsWith(".fsi")

type FormatSelectionRequest =
{
Expand All @@ -45,6 +42,7 @@ type FormatSelectionRequest =
/// Range follows the same semantics of the FSharp Compiler Range type.
Range: FormatSelectionRange
}
member this.IsSignatureFile = this.FilePath.EndsWith(".fsi")

and FormatSelectionRange =
struct
Expand All @@ -60,6 +58,16 @@ and FormatSelectionRange =
EndColumn = endColumn }
end

type FantomasResponse =
{
Code: int
FilePath: string
Content: string option
/// The actual range that was used to format a selection.
/// This can differ from the input selection range if the selection had leading or trailing whitespace.
SelectedRange: FormatSelectionRange option
}

type FantomasService =
interface
inherit IDisposable
Expand Down
Loading

0 comments on commit 4d98e26

Please sign in to comment.