From e671f3d7c68a258d80f6440ea82aaada2c48a34d Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Wed, 28 Jun 2023 08:44:23 +0200 Subject: [PATCH] V6.1 (#2913) * Expose TransformAST api. (#2868) * Expose TransformAST api. * Add additional unit test. * Revert changelog entry * Add Changelog for 6.1 alpha 1 * Enrich transformed Oak. (#2869) * Add Changelog for 6.1 alpha 2 * Rename FSharp.Compiler to Fantomas.FCS (#2894) * Rename FSharp.Compiler to Fantomas.FCS * Add release notes for 6.1.0-alpha-003. * Update editorconfig package (#2895) * Use EditorConfigCache. * Clean up EditorConfig.fs(i) * Add 6.1.0-alpha-004 to changelog. * Add 6.1.0-alpha-005 to changelog. * Add 6.1.0-alpha-006 to changelog. * Add stable release --- CHANGELOG.md | 31 ++++++++++ build.fsx | 13 ++++ docs/docs/end-users/GeneratingCode.fsx | 11 ++-- .../ASTTransformerTests.fs | 8 +-- src/Fantomas.Core.Tests/CodeFormatterTests.fs | 62 ++++++++++++++++++- .../CodePrinterHelperFunctionsTests.fs | 4 +- src/Fantomas.Core.Tests/CursorTests.fs | 2 +- src/Fantomas.Core.Tests/DefinesTests.fs | 2 +- .../FormattingSelectionOnlyTests.fs | 2 +- src/Fantomas.Core.Tests/SynLongIdentTests.fs | 8 +-- src/Fantomas.Core.Tests/TestHelpers.fs | 2 +- src/Fantomas.Core/ASTTransformer.fs | 10 +-- src/Fantomas.Core/ASTTransformer.fsi | 4 +- src/Fantomas.Core/CodeFormatter.fs | 11 +++- src/Fantomas.Core/CodeFormatter.fsi | 10 ++- src/Fantomas.Core/CodeFormatterImpl.fs | 6 +- src/Fantomas.Core/CodeFormatterImpl.fsi | 4 +- src/Fantomas.Core/CodeFormatterTypes.fs | 2 +- src/Fantomas.Core/CodePrinter.fs | 18 +++--- src/Fantomas.Core/Context.fs | 4 +- src/Fantomas.Core/Context.fsi | 2 +- src/Fantomas.Core/Defines.fs | 2 +- src/Fantomas.Core/Defines.fsi | 2 +- src/Fantomas.Core/ISourceTextExtensions.fs | 2 +- src/Fantomas.Core/ISourceTextExtensions.fsi | 2 +- .../MultipleDefineCombinations.fs | 2 +- src/Fantomas.Core/RangeHelpers.fs | 2 +- src/Fantomas.Core/RangeHelpers.fsi | 2 +- src/Fantomas.Core/Selection.fs | 2 +- src/Fantomas.Core/Selection.fsi | 2 +- src/Fantomas.Core/SyntaxOak.fs | 2 +- src/Fantomas.Core/Trivia.fs | 6 +- src/Fantomas.Core/Trivia.fsi | 4 +- src/Fantomas.Core/Validation.fs | 8 +-- src/Fantomas.FCS/Fantomas.FCS.fsproj | 12 ++-- src/Fantomas.FCS/Parse.fs | 34 +++++----- src/Fantomas.FCS/Parse.fsi | 6 +- src/Fantomas.Tests/packages.lock.json | 6 +- src/Fantomas/Daemon.fs | 2 +- src/Fantomas/EditorConfig.fs | 27 ++++---- src/Fantomas/EditorConfig.fsi | 2 - src/Fantomas/Fantomas.fsproj | 2 +- src/Fantomas/packages.lock.json | 6 +- 43 files changed, 232 insertions(+), 119 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d37d7ebd67..0eadc46154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Changelog +## 6.1.0 - 2023-06-27 + +Stable release + +## 6.1.0-alpha-006 - 2023-06-20 + +Contains fixes of 6.0.8 + +## 6.1.0-alpha-005 - 2023-06-20 + +Contains fixes of 6.0.7 + +## 6.1.0-alpha-004 - 2023-06-19 + +Contains fixes of 6.0.6 + +## 6.1.0-alpha-003 - 2023-06-02 + +### Changed +* Rename `namespace FSharp.Compiler` to `namespace Fantomas.FCS` for `Fantomas.FCS`. [#2894](https://github.com/fsprojects/fantomas/pull/2894) + +## 6.1.0-alpha-002 - 2023-05-02 + +### Changed +* Enrich transformed Oak. [#2869](https://github.com/fsprojects/fantomas/pull/2869) + +## 6.1.0-alpha-001 - 2023-05-02 + +### Added +* TransformAST in CodeFormatter. [#2868](https://github.com/fsprojects/fantomas/pull/2868) + ## [6.0.8] - 2023-06-20 ### Fixed diff --git a/build.fsx b/build.fsx index a92d96f872..567c44e7a0 100644 --- a/build.fsx +++ b/build.fsx @@ -193,6 +193,17 @@ let fsharpCompilerHash = let xDoc = XElement.Load(__SOURCE_DIRECTORY__ "Directory.Build.props") xDoc.XPathSelectElements("//FCSCommitHash") |> Seq.head |> (fun xe -> xe.Value) +let updateFileRaw (file: FileInfo) = + let lines = File.ReadAllLines file.FullName + let updatedLines = + lines + |> Array.map (fun line -> + if line.Contains("FSharp.Compiler") then + line.Replace("FSharp.Compiler", "Fantomas.FCS") + else + line) + File.WriteAllLines(file.FullName, updatedLines) + let downloadCompilerFile commitHash relativePath = async { let file = FileInfo(deps commitHash relativePath) @@ -213,6 +224,8 @@ let downloadCompilerFile commitHash relativePath = printfn $"Could not download %s{relativePath}" do! Async.AwaitTask(response.ResponseStream.CopyToAsync(fs)) fs.Close() + + updateFileRaw file } pipeline "Init" { diff --git a/docs/docs/end-users/GeneratingCode.fsx b/docs/docs/end-users/GeneratingCode.fsx index 4cec53a859..fb86a39527 100644 --- a/docs/docs/end-users/GeneratingCode.fsx +++ b/docs/docs/end-users/GeneratingCode.fsx @@ -33,9 +33,9 @@ To illustrate the API, lets generate a simple value binding: `let a = 0`. *) #r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.FCS.dll" -#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.Core.dll" // In production use #r "nuget: Fantomas.Core, 6.0-alpha-*" +#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.Core.dll" // In production use #r "nuget: Fantomas.Core, 6.*" -open FSharp.Compiler.Text +open Fantomas.FCS.Text open Fantomas.Core.SyntaxOak let implementationSyntaxTree = @@ -88,11 +88,8 @@ The more you interact with AST/Oak, the easier you pick up which node represents ### Fantomas.FCS -When looking at the example, we notice that we've opened `FSharp.Compiler.Text`. -Don't be fooled by this, `Fantomas.Core` and `Fantomas.FCS` **do not reference [FSharp.Compiler.Service](https://www.nuget.org/packages/FSharp.Compiler.Service)**! -Instead, `Fantomas.FCS` is a custom version of the F# compiler (built from source) that only exposes the F# parser and the syntax tree. - -`Fantomas.FCS` exposes the exact same namespaces because it builds from the exact same F# compiler source code. +When looking at the example, we notice that we've opened `Fantomas.FCS.Text`. +`Fantomas.FCS` is a custom version of the F# compiler (built from source) that only exposes the F# parser and the syntax tree. The key difference is that `Fantomas.FCS` will most likely contain a more recent version of the F# parser. You can read the [CHANGELOG](https://github.com/fsprojects/fantomas/blob/main/CHANGELOG.md) to see what git commit was used to build `Fantomas.FCS`. diff --git a/src/Fantomas.Core.Tests/ASTTransformerTests.fs b/src/Fantomas.Core.Tests/ASTTransformerTests.fs index 1afdff97a3..af3c60616a 100644 --- a/src/Fantomas.Core.Tests/ASTTransformerTests.fs +++ b/src/Fantomas.Core.Tests/ASTTransformerTests.fs @@ -1,10 +1,10 @@ module Fantomas.Core.Tests.ASTTransformerTests open NUnit.Framework -open FSharp.Compiler.Text -open FSharp.Compiler.Xml -open FSharp.Compiler.Syntax -open FSharp.Compiler.SyntaxTrivia +open Fantomas.FCS.Text +open Fantomas.FCS.Xml +open Fantomas.FCS.Syntax +open Fantomas.FCS.SyntaxTrivia open Fantomas.Core [] diff --git a/src/Fantomas.Core.Tests/CodeFormatterTests.fs b/src/Fantomas.Core.Tests/CodeFormatterTests.fs index 7b06ef4716..19a5d9a0e1 100644 --- a/src/Fantomas.Core.Tests/CodeFormatterTests.fs +++ b/src/Fantomas.Core.Tests/CodeFormatterTests.fs @@ -1,7 +1,9 @@ module Fantomas.Core.Tests.CodeFormatterTests open NUnit.Framework +open Fantomas.FCS.Text open Fantomas.Core +open Fantomas.Core.SyntaxOak open Fantomas.Core.Tests.TestHelpers [] @@ -39,7 +41,7 @@ let main _ = |> ignore [] -let ``trivia is parsed for Oak`` () = +let ``trivia is transformed to Oak`` () = let oak = CodeFormatter.ParseOakAsync(false, "let a = 0\n // foo") |> Async.RunSynchronously @@ -67,3 +69,61 @@ let ``parsed oak can be formatted back to source`` () = |> Async.RunSynchronously Assert.AreEqual(source, formatted) + +[] +let ``transform parsedInput to Oak`` () = + let source = + """ +module A + +#if DEBUG +let b = 0 +#endif +""" + + let ast, _ = + Fantomas.FCS.Parse.parseFile false (SourceText.ofString source) [ "DEBUG" ] + + let oak = CodeFormatter.TransformAST(ast, source) + + match oak.ModulesOrNamespaces.[0].Declarations.[0] with + | ModuleDecl.TopLevelBinding _ -> Assert.Pass() + | _ -> Assert.Fail() + +[] +let ``transform parsedInput created with additional defines to Oak`` () = + let source = + """ +module A + +#if DEBUG +let b = 0 +#endif +""" + + let ast, _ = + Fantomas.FCS.Parse.parseFile false (SourceText.ofString source) [ "DEBUG"; "FOO"; "BAR" ] + + let oak = CodeFormatter.TransformAST ast + + match oak.ModulesOrNamespaces.[0].Declarations.[0] with + | ModuleDecl.TopLevelBinding _ -> Assert.Pass() + | _ -> Assert.Fail() + +[] +let ``transform parsedInput contains trivia in Oak`` () = + let source = + """ +module A + +// foo +let b = 0 +""" + + let ast, _ = Fantomas.FCS.Parse.parseFile false (SourceText.ofString source) [] + + let oak = CodeFormatter.TransformAST(ast, source) + + match oak.ModulesOrNamespaces.[0].Declarations.[0] with + | ModuleDecl.TopLevelBinding node -> Assert.True node.HasContentBefore + | _ -> Assert.Fail() diff --git a/src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs b/src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs index 464a6e64a0..388d4985fb 100644 --- a/src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs +++ b/src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs @@ -209,7 +209,7 @@ let a = // Let's create a dummy Oak // In practise, a FCS Syntax tree will be transformed to an Oak - let zeroRange = FSharp.Compiler.Text.Range.Zero + let zeroRange = Fantomas.FCS.Text.Range.Zero let stn text = SingleTextNode(text, zeroRange) let tree = @@ -321,7 +321,7 @@ let b = 2 """ // Imagine that we always want to print a new line between let bindings. - let zeroRange = FSharp.Compiler.Text.Range.Zero + let zeroRange = Fantomas.FCS.Text.Range.Zero let stn text = SingleTextNode(text, zeroRange) let mkBinding name body = diff --git a/src/Fantomas.Core.Tests/CursorTests.fs b/src/Fantomas.Core.Tests/CursorTests.fs index 8667d8028b..08c1d683f9 100644 --- a/src/Fantomas.Core.Tests/CursorTests.fs +++ b/src/Fantomas.Core.Tests/CursorTests.fs @@ -1,6 +1,6 @@ module Fantomas.Core.Tests.CursorTests -open FSharp.Compiler.Text +open Fantomas.FCS.Text open NUnit.Framework open FsUnit open Fantomas.Core diff --git a/src/Fantomas.Core.Tests/DefinesTests.fs b/src/Fantomas.Core.Tests/DefinesTests.fs index 7e05807829..04cfe97f50 100644 --- a/src/Fantomas.Core.Tests/DefinesTests.fs +++ b/src/Fantomas.Core.Tests/DefinesTests.fs @@ -2,7 +2,7 @@ module Fantomas.Core.Tests.TokenParserTests open NUnit.Framework open FsUnit -open FSharp.Compiler.Syntax +open Fantomas.FCS.Syntax open Fantomas.Core open Fantomas.Core.Defines open Fantomas.Core.Tests.TestHelpers diff --git a/src/Fantomas.Core.Tests/FormattingSelectionOnlyTests.fs b/src/Fantomas.Core.Tests/FormattingSelectionOnlyTests.fs index e555a4e469..6099d0d19a 100644 --- a/src/Fantomas.Core.Tests/FormattingSelectionOnlyTests.fs +++ b/src/Fantomas.Core.Tests/FormattingSelectionOnlyTests.fs @@ -1,6 +1,6 @@ module Fantomas.Core.Tests.FormattingSelectionOnlyTests -open FSharp.Compiler.Text +open Fantomas.FCS.Text open Fantomas.Core open NUnit.Framework open FsUnit diff --git a/src/Fantomas.Core.Tests/SynLongIdentTests.fs b/src/Fantomas.Core.Tests/SynLongIdentTests.fs index 430db0a169..2858d79938 100644 --- a/src/Fantomas.Core.Tests/SynLongIdentTests.fs +++ b/src/Fantomas.Core.Tests/SynLongIdentTests.fs @@ -1,9 +1,9 @@ module Fantomas.Core.Tests.SynLongIdentTests -open FSharp.Compiler.Text -open FSharp.Compiler.Syntax -open FSharp.Compiler.SyntaxTrivia -open FSharp.Compiler.Xml +open Fantomas.FCS.Text +open Fantomas.FCS.Syntax +open Fantomas.FCS.SyntaxTrivia +open Fantomas.FCS.Xml open NUnit.Framework open FsUnit open Fantomas.Core diff --git a/src/Fantomas.Core.Tests/TestHelpers.fs b/src/Fantomas.Core.Tests/TestHelpers.fs index 13bae076e5..cd096ad867 100644 --- a/src/Fantomas.Core.Tests/TestHelpers.fs +++ b/src/Fantomas.Core.Tests/TestHelpers.fs @@ -40,7 +40,7 @@ let formatSourceString isFsiFile (s: string) config = let formatAST isFsiFile (source: string) config = async { let ast, _ = - Fantomas.FCS.Parse.parseFile isFsiFile (FSharp.Compiler.Text.SourceText.ofString source) [] + Fantomas.FCS.Parse.parseFile isFsiFile (Fantomas.FCS.Text.SourceText.ofString source) [] let! formattedCode = CodeFormatter.FormatASTAsync(ast, config = config) let! isValid = CodeFormatter.IsValidFSharpCodeAsync(isFsiFile, formattedCode) diff --git a/src/Fantomas.Core/ASTTransformer.fs b/src/Fantomas.Core/ASTTransformer.fs index 3981690302..e9cec7cb80 100644 --- a/src/Fantomas.Core/ASTTransformer.fs +++ b/src/Fantomas.Core/ASTTransformer.fs @@ -2,11 +2,11 @@ open System.Collections.Generic open System.Text.RegularExpressions -open FSharp.Compiler.Text -open FSharp.Compiler.Text.Range -open FSharp.Compiler.Syntax -open FSharp.Compiler.SyntaxTrivia -open FSharp.Compiler.Xml +open Fantomas.FCS.Text +open Fantomas.FCS.Text.Range +open Fantomas.FCS.Syntax +open Fantomas.FCS.SyntaxTrivia +open Fantomas.FCS.Xml open Fantomas.Core.ISourceTextExtensions open Fantomas.Core.RangePatterns open Fantomas.Core.SyntaxOak diff --git a/src/Fantomas.Core/ASTTransformer.fsi b/src/Fantomas.Core/ASTTransformer.fsi index 1a3a10fd55..1b0a8fe6db 100644 --- a/src/Fantomas.Core/ASTTransformer.fsi +++ b/src/Fantomas.Core/ASTTransformer.fsi @@ -1,7 +1,7 @@ module internal Fantomas.Core.ASTTransformer -open FSharp.Compiler.Text -open FSharp.Compiler.Syntax +open Fantomas.FCS.Text +open Fantomas.FCS.Syntax open Fantomas.Core.SyntaxOak val mkOak: sourceText: ISourceText option -> ast: ParsedInput -> Oak diff --git a/src/Fantomas.Core/CodeFormatter.fs b/src/Fantomas.Core/CodeFormatter.fs index bff11ccd2e..de70e9071d 100644 --- a/src/Fantomas.Core/CodeFormatter.fs +++ b/src/Fantomas.Core/CodeFormatter.fs @@ -1,7 +1,7 @@ namespace Fantomas.Core -open FSharp.Compiler.Syntax -open FSharp.Compiler.Text +open Fantomas.FCS.Syntax +open Fantomas.FCS.Text open Fantomas.Core.SyntaxOak [] @@ -78,6 +78,13 @@ type CodeFormatter = oak, defines.Value) } + static member TransformAST ast = ASTTransformer.mkOak None ast + + static member TransformAST(ast, source) = + let sourceText = SourceText.ofString source + let oak = ASTTransformer.mkOak (Some sourceText) ast + Trivia.enrichTree FormatConfig.Default sourceText ast oak + static member FormatOakAsync(oak: Oak) : Async = async { let context = Context.Context.Create FormatConfig.Default diff --git a/src/Fantomas.Core/CodeFormatter.fsi b/src/Fantomas.Core/CodeFormatter.fsi index edf6cfb71e..85fb76c538 100644 --- a/src/Fantomas.Core/CodeFormatter.fsi +++ b/src/Fantomas.Core/CodeFormatter.fsi @@ -1,7 +1,7 @@ namespace Fantomas.Core -open FSharp.Compiler.Text -open FSharp.Compiler.Syntax +open Fantomas.FCS.Text +open Fantomas.FCS.Syntax open Fantomas.Core.SyntaxOak [] @@ -67,6 +67,12 @@ type CodeFormatter = /// Parse a source string to SyntaxOak static member ParseOakAsync: isSignature: bool * source: string -> Async<(Oak * string list) array> + /// Transform a ParsedInput to an Oak + static member TransformAST: ast: ParsedInput -> Oak + + /// Transform a ParsedInput to an Oak + static member TransformAST: ast: ParsedInput * source: string -> Oak + /// Format SyntaxOak to string static member FormatOakAsync: oak: Oak -> Async diff --git a/src/Fantomas.Core/CodeFormatterImpl.fs b/src/Fantomas.Core/CodeFormatterImpl.fs index 857eeea741..553797e3a5 100644 --- a/src/Fantomas.Core/CodeFormatterImpl.fs +++ b/src/Fantomas.Core/CodeFormatterImpl.fs @@ -1,9 +1,9 @@ [] module internal Fantomas.Core.CodeFormatterImpl -open FSharp.Compiler.Diagnostics -open FSharp.Compiler.Syntax -open FSharp.Compiler.Text +open Fantomas.FCS.Diagnostics +open Fantomas.FCS.Syntax +open Fantomas.FCS.Text open MultipleDefineCombinations let getSourceText (source: string) : ISourceText = source.TrimEnd() |> SourceText.ofString diff --git a/src/Fantomas.Core/CodeFormatterImpl.fsi b/src/Fantomas.Core/CodeFormatterImpl.fsi index 83fbb373cb..cc6d80aa6a 100644 --- a/src/Fantomas.Core/CodeFormatterImpl.fsi +++ b/src/Fantomas.Core/CodeFormatterImpl.fsi @@ -1,8 +1,8 @@ [] module internal Fantomas.Core.CodeFormatterImpl -open FSharp.Compiler.Syntax -open FSharp.Compiler.Text +open Fantomas.FCS.Syntax +open Fantomas.FCS.Text val getSourceText: source: string -> ISourceText diff --git a/src/Fantomas.Core/CodeFormatterTypes.fs b/src/Fantomas.Core/CodeFormatterTypes.fs index 13e536e24c..9aac6a9d1a 100644 --- a/src/Fantomas.Core/CodeFormatterTypes.fs +++ b/src/Fantomas.Core/CodeFormatterTypes.fs @@ -1,6 +1,6 @@ namespace Fantomas.Core -open FSharp.Compiler.Text +open Fantomas.FCS.Text type FormatResult = { diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index f0930b3681..b5bc54b4c0 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -102,7 +102,7 @@ let genTrivia (node: Node) (trivia: TriviaNode) (ctx: Context) = let originalColumnOffset = trivia.Range.EndColumn - node.Range.EndColumn let formattedCursor = - FSharp.Compiler.Text.Position.mkPos ctx.WriterModel.Lines.Length (ctx.Column + originalColumnOffset) + Fantomas.FCS.Text.Position.mkPos ctx.WriterModel.Lines.Length (ctx.Column + originalColumnOffset) { ctx with FormattedCursor = Some formattedCursor } @@ -122,7 +122,7 @@ let recordCursorNode f (node: Node) (ctx: Context) = let formattedCursor = let columnOffsetInSource = cursor.Column - node.Range.StartColumn - FSharp.Compiler.Text.Position.mkPos currentStartLine (currentStartColumn + columnOffsetInSource) + Fantomas.FCS.Text.Position.mkPos currentStartLine (currentStartColumn + columnOffsetInSource) { ctxAfter with FormattedCursor = Some formattedCursor } @@ -766,7 +766,7 @@ let genExpr (e: Expr) = | [] -> genExpr node.LeadingExpr | (operator, e2) :: es -> let m = - FSharp.Compiler.Text.Range.unionRanges (Expr.Node node.LeadingExpr).Range (Expr.Node e2).Range + Fantomas.FCS.Text.Range.unionRanges (Expr.Node node.LeadingExpr).Range (Expr.Node e2).Range genMultilineInfixExpr (ExprInfixAppNode(node.LeadingExpr, operator, e2, m)) +> sepNln @@ -1045,9 +1045,9 @@ let genExpr (e: Expr) = let parenExpr = mkExprParenNode node.OpeningParen - (Expr.Null(SingleTextNode("", FSharp.Compiler.Text.Range.Zero))) + (Expr.Null(SingleTextNode("", Fantomas.FCS.Text.Range.Zero))) node.ClosingParen - FSharp.Compiler.Text.Range.Zero + Fantomas.FCS.Text.Range.Zero sepSpaceBeforeParenInFuncInvocation node.FunctionName parenExpr | _ -> sepSpace @@ -1839,16 +1839,16 @@ let genTupleExpr (node: ExprTupleNode) = | IsLambdaOrIfThenElse e -> let parenNode = mkExprParenNode - (SingleTextNode("(", FSharp.Compiler.Text.Range.Zero)) + (SingleTextNode("(", Fantomas.FCS.Text.Range.Zero)) e - (SingleTextNode(")", FSharp.Compiler.Text.Range.Zero)) - FSharp.Compiler.Text.Range.Zero + (SingleTextNode(")", Fantomas.FCS.Text.Range.Zero)) + Fantomas.FCS.Text.Range.Zero ExprInfixAppNode( exprInfixAppNode.LeftHandSide, exprInfixAppNode.Operator, parenNode, - FSharp.Compiler.Text.range.Zero + Fantomas.FCS.Text.range.Zero ) |> Expr.InfixApp | _ -> expr diff --git a/src/Fantomas.Core/Context.fs b/src/Fantomas.Core/Context.fs index 3c906a23cf..4c2b797d94 100644 --- a/src/Fantomas.Core/Context.fs +++ b/src/Fantomas.Core/Context.fs @@ -1,7 +1,7 @@ module internal Fantomas.Core.Context open System -open FSharp.Compiler.Text +open Fantomas.FCS.Text open Fantomas.Core open Fantomas.Core.SyntaxOak @@ -375,7 +375,7 @@ let newlineBetweenLastWriteEvent ctx = let lastWriteEventOnLastLine ctx = writeEventsOnLastLine ctx |> Seq.tryHead -// A few utility functions from https://github.com/fsharp/powerpack/blob/master/src/FSharp.Compiler.CodeDom/generator.fs +// A few utility functions from https://github.com/fsharp/powerpack/blob/master/src/Fantomas.FCS.CodeDom/generator.fs /// Indent one more level based on configuration let indent (ctx: Context) = diff --git a/src/Fantomas.Core/Context.fsi b/src/Fantomas.Core/Context.fsi index 80e4d4921e..8eb6b77341 100644 --- a/src/Fantomas.Core/Context.fsi +++ b/src/Fantomas.Core/Context.fsi @@ -1,6 +1,6 @@ module internal Fantomas.Core.Context -open FSharp.Compiler.Text +open Fantomas.FCS.Text open Fantomas.Core.SyntaxOak type WriterEvent = diff --git a/src/Fantomas.Core/Defines.fs b/src/Fantomas.Core/Defines.fs index a80f0900bf..bdb30a1017 100644 --- a/src/Fantomas.Core/Defines.fs +++ b/src/Fantomas.Core/Defines.fs @@ -1,6 +1,6 @@ namespace Fantomas.Core -open FSharp.Compiler.SyntaxTrivia +open Fantomas.FCS.SyntaxTrivia open Fantomas.Core type internal DefineCombination = diff --git a/src/Fantomas.Core/Defines.fsi b/src/Fantomas.Core/Defines.fsi index e3d2381c0e..5f9709b552 100644 --- a/src/Fantomas.Core/Defines.fsi +++ b/src/Fantomas.Core/Defines.fsi @@ -8,6 +8,6 @@ type internal DefineCombination = static member Empty: DefineCombination module internal Defines = - open FSharp.Compiler.SyntaxTrivia + open Fantomas.FCS.SyntaxTrivia val getDefineCombination: hashDirectives: ConditionalDirectiveTrivia list -> DefineCombination list diff --git a/src/Fantomas.Core/ISourceTextExtensions.fs b/src/Fantomas.Core/ISourceTextExtensions.fs index 9df2c86ab4..bb5ac709d6 100644 --- a/src/Fantomas.Core/ISourceTextExtensions.fs +++ b/src/Fantomas.Core/ISourceTextExtensions.fs @@ -1,7 +1,7 @@ module Fantomas.Core.ISourceTextExtensions open System.Text -open FSharp.Compiler.Text +open Fantomas.FCS.Text type ISourceText with diff --git a/src/Fantomas.Core/ISourceTextExtensions.fsi b/src/Fantomas.Core/ISourceTextExtensions.fsi index 2b43298cfd..22dc4d2976 100644 --- a/src/Fantomas.Core/ISourceTextExtensions.fsi +++ b/src/Fantomas.Core/ISourceTextExtensions.fsi @@ -1,6 +1,6 @@ module Fantomas.Core.ISourceTextExtensions -open FSharp.Compiler.Text +open Fantomas.FCS.Text type ISourceText with diff --git a/src/Fantomas.Core/MultipleDefineCombinations.fs b/src/Fantomas.Core/MultipleDefineCombinations.fs index 22bb175a85..34e4634fe0 100644 --- a/src/Fantomas.Core/MultipleDefineCombinations.fs +++ b/src/Fantomas.Core/MultipleDefineCombinations.fs @@ -5,7 +5,7 @@ open System.Linq open System.Text open System.Text.RegularExpressions open Microsoft.FSharp.Core.CompilerServices -open FSharp.Compiler.Text +open Fantomas.FCS.Text /// A CodeFragment represents a chunk of code that is either /// a single conditional hash directive line, diff --git a/src/Fantomas.Core/RangeHelpers.fs b/src/Fantomas.Core/RangeHelpers.fs index 057d0f6d47..16f3863cd6 100644 --- a/src/Fantomas.Core/RangeHelpers.fs +++ b/src/Fantomas.Core/RangeHelpers.fs @@ -1,6 +1,6 @@ namespace Fantomas.Core -open FSharp.Compiler.Text +open Fantomas.FCS.Text [] module RangeHelpers = diff --git a/src/Fantomas.Core/RangeHelpers.fsi b/src/Fantomas.Core/RangeHelpers.fsi index ed23ccc362..36033b7534 100644 --- a/src/Fantomas.Core/RangeHelpers.fsi +++ b/src/Fantomas.Core/RangeHelpers.fsi @@ -1,6 +1,6 @@ namespace Fantomas.Core -open FSharp.Compiler.Text +open Fantomas.FCS.Text [] module RangeHelpers = diff --git a/src/Fantomas.Core/Selection.fs b/src/Fantomas.Core/Selection.fs index bff65e4bbe..f2e38b6eab 100644 --- a/src/Fantomas.Core/Selection.fs +++ b/src/Fantomas.Core/Selection.fs @@ -1,6 +1,6 @@ module internal Fantomas.Core.Selection -open FSharp.Compiler.Text +open Fantomas.FCS.Text open Fantomas.Core.SyntaxOak open Fantomas.Core.ISourceTextExtensions diff --git a/src/Fantomas.Core/Selection.fsi b/src/Fantomas.Core/Selection.fsi index dde98cd52f..834ab23294 100644 --- a/src/Fantomas.Core/Selection.fsi +++ b/src/Fantomas.Core/Selection.fsi @@ -1,6 +1,6 @@ module internal Fantomas.Core.Selection -open FSharp.Compiler.Text +open Fantomas.FCS.Text val formatSelection: config: FormatConfig -> isSignature: bool -> selection: range -> sourceText: ISourceText -> Async diff --git a/src/Fantomas.Core/SyntaxOak.fs b/src/Fantomas.Core/SyntaxOak.fs index 09d3f54b58..ea9908ac92 100644 --- a/src/Fantomas.Core/SyntaxOak.fs +++ b/src/Fantomas.Core/SyntaxOak.fs @@ -1,7 +1,7 @@ module rec Fantomas.Core.SyntaxOak open System.Collections.Generic -open FSharp.Compiler.Text +open Fantomas.FCS.Text type TriviaContent = | CommentOnSingleLine of string diff --git a/src/Fantomas.Core/Trivia.fs b/src/Fantomas.Core/Trivia.fs index da4678425c..8f06765158 100644 --- a/src/Fantomas.Core/Trivia.fs +++ b/src/Fantomas.Core/Trivia.fs @@ -1,8 +1,8 @@ module internal Fantomas.Core.Trivia -open FSharp.Compiler.Syntax -open FSharp.Compiler.SyntaxTrivia -open FSharp.Compiler.Text +open Fantomas.FCS.Syntax +open Fantomas.FCS.SyntaxTrivia +open Fantomas.FCS.Text open Fantomas.Core.ISourceTextExtensions open Fantomas.Core.SyntaxOak diff --git a/src/Fantomas.Core/Trivia.fsi b/src/Fantomas.Core/Trivia.fsi index 5ecb7272cb..ce6a0d7276 100644 --- a/src/Fantomas.Core/Trivia.fsi +++ b/src/Fantomas.Core/Trivia.fsi @@ -1,7 +1,7 @@ module internal Fantomas.Core.Trivia -open FSharp.Compiler.Syntax -open FSharp.Compiler.Text +open Fantomas.FCS.Syntax +open Fantomas.FCS.Text open Fantomas.Core.SyntaxOak val findNodeWhereRangeFitsIn: root: Node -> range: range -> Node option diff --git a/src/Fantomas.Core/Validation.fs b/src/Fantomas.Core/Validation.fs index 41498503bb..01d78a9583 100644 --- a/src/Fantomas.Core/Validation.fs +++ b/src/Fantomas.Core/Validation.fs @@ -1,8 +1,8 @@ module internal Fantomas.Core.Validation -open FSharp.Compiler.Diagnostics -open FSharp.Compiler.Text -open FSharp.Compiler.Syntax +open Fantomas.FCS.Diagnostics +open Fantomas.FCS.Text +open Fantomas.FCS.Syntax open Fantomas.FCS.Parse let private safeToIgnoreWarnings = @@ -10,7 +10,7 @@ let private safeToIgnoreWarnings = [ "This construct is deprecated: it is only for use in the F# library" "Identifiers containing '@' are reserved for use in F# code generation" ] -// Exception of type 'FSharp.Compiler.DiagnosticsLogger+LibraryUseOnly' was thrown. +// Exception of type 'Fantomas.FCS.DiagnosticsLogger+LibraryUseOnly' was thrown. let noWarningOrErrorDiagnostics diagnostics = let errors = diff --git a/src/Fantomas.FCS/Fantomas.FCS.fsproj b/src/Fantomas.FCS/Fantomas.FCS.fsproj index 75131bca54..3df4e6f1cc 100644 --- a/src/Fantomas.FCS/Fantomas.FCS.fsproj +++ b/src/Fantomas.FCS/Fantomas.FCS.fsproj @@ -174,14 +174,14 @@ Facilities\prim-parsing.fs - --module FSharp.Compiler.AbstractIL.AsciiLexer --internal --open Internal.Utilities.Text.Lexing --open FSharp.Compiler.AbstractIL.AsciiParser --unicode --lexlib Internal.Utilities.Text.Lexing + --module Fantomas.FCS.AbstractIL.AsciiLexer --internal --open Internal.Utilities.Text.Lexing --open Fantomas.FCS.AbstractIL.AsciiParser --unicode --lexlib Internal.Utilities.Text.Lexing AbstractIL\illex.fsl AbstractIL\illex.fsl - --module FSharp.Compiler.AbstractIL.AsciiParser --open FSharp.Compiler.AbstractIL --open FSharp.Compiler.AbstractIL.AsciiConstants --open FSharp.Compiler.AbstractIL.IL --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing --buffer-type-argument char + --module Fantomas.FCS.AbstractIL.AsciiParser --open Fantomas.FCS.AbstractIL --open Fantomas.FCS.AbstractIL.AsciiConstants --open Fantomas.FCS.AbstractIL.IL --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing --buffer-type-argument char AbstractIL\ilpars.fsy @@ -224,19 +224,19 @@ SyntaxTree\PrettyNaming.fs - --module FSharp.Compiler.PPLexer --internal --open FSharp.Compiler.Lexhelp --open Internal.Utilities.Text.Lexing --open FSharp.Compiler.PPParser --unicode --lexlib Internal.Utilities.Text.Lexing + --module Fantomas.FCS.PPLexer --internal --open Fantomas.FCS.Lexhelp --open Internal.Utilities.Text.Lexing --open Fantomas.FCS.PPParser --unicode --lexlib Internal.Utilities.Text.Lexing SyntaxTree\pplex.fsl - --module FSharp.Compiler.PPParser --open FSharp.Compiler --open FSharp.Compiler.Syntax --open FSharp.Compiler.ParseHelpers --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing --buffer-type-argument char + --module Fantomas.FCS.PPParser --open Fantomas.FCS --open Fantomas.FCS.Syntax --open Fantomas.FCS.ParseHelpers --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing --buffer-type-argument char SyntaxTree\pppars.fsy - --module FSharp.Compiler.Lexer --open FSharp.Compiler.Lexhelp --open Internal.Utilities.Text.Lexing --open FSharp.Compiler.Parser --open FSharp.Compiler.Text --open FSharp.Compiler.ParseHelpers --internal --unicode --lexlib Internal.Utilities.Text.Lexing + --module Fantomas.FCS.Lexer --open Fantomas.FCS.Lexhelp --open Internal.Utilities.Text.Lexing --open Fantomas.FCS.Parser --open Fantomas.FCS.Text --open Fantomas.FCS.ParseHelpers --internal --unicode --lexlib Internal.Utilities.Text.Lexing SyntaxTree\lex.fsl - -v --module FSharp.Compiler.Parser --open FSharp.Compiler --open FSharp.Compiler.Syntax --open FSharp.Compiler.Text --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing --buffer-type-argument char + -v --module Fantomas.FCS.Parser --open Fantomas.FCS --open Fantomas.FCS.Syntax --open Fantomas.FCS.Text --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing --buffer-type-argument char SyntaxTree\pars.fsy diff --git a/src/Fantomas.FCS/Parse.fs b/src/Fantomas.FCS/Parse.fs index d87b34666c..8443a9e173 100644 --- a/src/Fantomas.FCS/Parse.fs +++ b/src/Fantomas.FCS/Parse.fs @@ -3,25 +3,25 @@ module Fantomas.FCS.Parse open System open System.Text open System.Diagnostics -open FSharp.Compiler.Diagnostics -open FSharp.Compiler.DiagnosticMessage +open Fantomas.FCS.Diagnostics +open Fantomas.FCS.DiagnosticMessage open Internal.Utilities open Internal.Utilities.Library -open FSharp.Compiler -open FSharp.Compiler.AbstractIL.IL -open FSharp.Compiler.DiagnosticsLogger -open FSharp.Compiler.Features -open FSharp.Compiler.Lexhelp -open FSharp.Compiler.Text -open FSharp.Compiler.Text.Position -open FSharp.Compiler.Text.Range -open FSharp.Compiler.Xml -open FSharp.Compiler.Syntax -open FSharp.Compiler.SyntaxTrivia -open FSharp.Compiler.Syntax.PrettyNaming -open FSharp.Compiler.SyntaxTreeOps -open FSharp.Compiler.IO -open FSharp.Compiler.ParseHelpers +open Fantomas.FCS +open Fantomas.FCS.AbstractIL.IL +open Fantomas.FCS.DiagnosticsLogger +open Fantomas.FCS.Features +open Fantomas.FCS.Lexhelp +open Fantomas.FCS.Text +open Fantomas.FCS.Text.Position +open Fantomas.FCS.Text.Range +open Fantomas.FCS.Xml +open Fantomas.FCS.Syntax +open Fantomas.FCS.SyntaxTrivia +open Fantomas.FCS.Syntax.PrettyNaming +open Fantomas.FCS.SyntaxTreeOps +open Fantomas.FCS.IO +open Fantomas.FCS.ParseHelpers let FSharpSigFileSuffixes = [ ".mli"; ".fsi" ] diff --git a/src/Fantomas.FCS/Parse.fsi b/src/Fantomas.FCS/Parse.fsi index f19f7ece76..31b7aded9b 100644 --- a/src/Fantomas.FCS/Parse.fsi +++ b/src/Fantomas.FCS/Parse.fsi @@ -1,8 +1,8 @@ module Fantomas.FCS.Parse -open FSharp.Compiler.Diagnostics -open FSharp.Compiler.Syntax -open FSharp.Compiler.Text +open Fantomas.FCS.Diagnostics +open Fantomas.FCS.Syntax +open Fantomas.FCS.Text type FSharpParserDiagnostic = { Severity: FSharpDiagnosticSeverity diff --git a/src/Fantomas.Tests/packages.lock.json b/src/Fantomas.Tests/packages.lock.json index ae6e7d4352..755eb6d456 100644 --- a/src/Fantomas.Tests/packages.lock.json +++ b/src/Fantomas.Tests/packages.lock.json @@ -73,8 +73,8 @@ }, "editorconfig": { "type": "Transitive", - "resolved": "0.13.0", - "contentHash": "1IAdbakbxaKyVv/gr3VTHkbFMFgfOSpP4VRSvOg50Ee9qAfXDr4F8FvOtwq7Pi6fcoxxXYfOYceT1U3oODdpFg==" + "resolved": "0.14.0", + "contentHash": "emt1KlBtTsTSHWeLnlD1grQYN991wlzIh8t0/HF8ambYTLE8v25sPU9q2eu3sNj/Za7Ij6a0MW00lDGTsphEhQ==" }, "Fable.Core": { "type": "Transitive", @@ -922,7 +922,7 @@ "StreamJsonRpc": "[2.8.28, )", "System.IO.Abstractions": "[17.2.3, )", "Thoth.Json.Net": "[8.0.0, )", - "editorconfig": "[0.13.0, )" + "editorconfig": "[0.14.0, )" } }, "fantomas.client": { diff --git a/src/Fantomas/Daemon.fs b/src/Fantomas/Daemon.fs index f8169b28aa..b06bc19a88 100644 --- a/src/Fantomas/Daemon.fs +++ b/src/Fantomas/Daemon.fs @@ -8,7 +8,7 @@ open System.Threading open System.Threading.Tasks open StreamJsonRpc open Thoth.Json.Net -open FSharp.Compiler.Text +open Fantomas.FCS.Text open Fantomas.Client.Contracts open Fantomas.Client.LSPFantomasServiceTypes open Fantomas.Core diff --git a/src/Fantomas/EditorConfig.fs b/src/Fantomas/EditorConfig.fs index 8f5e4d6908..f362fe4ba6 100644 --- a/src/Fantomas/EditorConfig.fs +++ b/src/Fantomas/EditorConfig.fs @@ -2,6 +2,7 @@ module Fantomas.EditorConfig open System.Collections.Generic open System.ComponentModel +open EditorConfig.Core open Fantomas.Core module Reflection = @@ -15,7 +16,7 @@ module Reflection = DisplayName: string option Description: string option } - let inline private getCustomAttribute<'t, 'v when 't :> Attribute and 't: null> + let inline getCustomAttribute<'t, 'v when 't :> Attribute and 't: null> (projection: 't -> 'v) (property: PropertyInfo) : 'v option = @@ -40,7 +41,7 @@ let toEditorConfigName value = value |> Seq.map (fun c -> if System.Char.IsUpper(c) then - sprintf "_%s" (c.ToString().ToLower()) + $"_%s{c.ToString().ToLower()}" else c.ToString()) |> String.concat "" @@ -49,28 +50,28 @@ let toEditorConfigName value = if List.contains name supportedProperties then name else - sprintf "fsharp_%s" name + $"fsharp_%s{name}" -let private getFantomasFields (fallbackConfig: FormatConfig) = +let getFantomasFields (fallbackConfig: FormatConfig) = Reflection.getRecordFields fallbackConfig |> Array.map (fun (recordField, defaultValue) -> let editorConfigName = toEditorConfigName recordField.PropertyName (editorConfigName, defaultValue)) -let private (|Number|_|) (d: string) = +let (|Number|_|) (d: string) = match System.Int32.TryParse(d) with | true, d -> Some(box d) | _ -> None -let private (|MultilineFormatterType|_|) mft = +let (|MultilineFormatterType|_|) mft = MultilineFormatterType.OfConfigString mft -let private (|BracketStyle|_|) bs = MultilineBracketStyle.OfConfigString bs +let (|BracketStyle|_|) bs = MultilineBracketStyle.OfConfigString bs -let private (|EndOfLineStyle|_|) eol = EndOfLineStyle.OfConfigString eol +let (|EndOfLineStyle|_|) eol = EndOfLineStyle.OfConfigString eol -let private (|Boolean|_|) b = +let (|Boolean|_|) b = if b = "true" then Some(box true) elif b = "false" then Some(box false) else None @@ -102,18 +103,18 @@ let configToEditorConfig (config: FormatConfig) : string = |> Some | :? System.Int32 as i -> $"%s{toEditorConfigName recordField.PropertyName}=%d{i}" |> Some | :? MultilineFormatterType as mft -> - sprintf "%s=%s" (toEditorConfigName recordField.PropertyName) (MultilineFormatterType.ToConfigString mft) + $"%s{toEditorConfigName recordField.PropertyName}=%s{MultilineFormatterType.ToConfigString mft}" |> Some | :? EndOfLineStyle as eols -> - sprintf "%s=%s" (toEditorConfigName recordField.PropertyName) (EndOfLineStyle.ToConfigString eols) + $"%s{toEditorConfigName recordField.PropertyName}=%s{EndOfLineStyle.ToConfigString eols}" |> Some | _ -> None) |> String.concat "\n" -let private editorConfigParser = EditorConfig.Core.EditorConfigParser() +let editorConfigParser = EditorConfigParser(EditorConfigFileCache.GetOrCreate) let tryReadConfiguration (fsharpFile: string) : FormatConfig option = - let editorConfigSettings: EditorConfig.Core.FileConfiguration = + let editorConfigSettings: FileConfiguration = editorConfigParser.Parse(fileName = fsharpFile) if editorConfigSettings.Properties.Count = 0 then diff --git a/src/Fantomas/EditorConfig.fsi b/src/Fantomas/EditorConfig.fsi index 814eaa0597..e0209e2ce8 100644 --- a/src/Fantomas/EditorConfig.fsi +++ b/src/Fantomas/EditorConfig.fsi @@ -12,8 +12,6 @@ module Reflection = val inline getRecordFields: x: 'a -> (FSharpRecordField * obj)[] -val supportedProperties: string list - val toEditorConfigName: value: seq -> string val parseOptionsFromEditorConfig: diff --git a/src/Fantomas/Fantomas.fsproj b/src/Fantomas/Fantomas.fsproj index e156216af1..34a5d5eaa4 100644 --- a/src/Fantomas/Fantomas.fsproj +++ b/src/Fantomas/Fantomas.fsproj @@ -41,7 +41,7 @@ - + diff --git a/src/Fantomas/packages.lock.json b/src/Fantomas/packages.lock.json index 5342a0e51f..2bb8c55aea 100644 --- a/src/Fantomas/packages.lock.json +++ b/src/Fantomas/packages.lock.json @@ -26,9 +26,9 @@ }, "editorconfig": { "type": "Direct", - "requested": "[0.13.0, )", - "resolved": "0.13.0", - "contentHash": "1IAdbakbxaKyVv/gr3VTHkbFMFgfOSpP4VRSvOg50Ee9qAfXDr4F8FvOtwq7Pi6fcoxxXYfOYceT1U3oODdpFg==" + "requested": "[0.14.0, )", + "resolved": "0.14.0", + "contentHash": "emt1KlBtTsTSHWeLnlD1grQYN991wlzIh8t0/HF8ambYTLE8v25sPU9q2eu3sNj/Za7Ij6a0MW00lDGTsphEhQ==" }, "FSharp.Core": { "type": "Direct",