diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f9e15830d4..6dbe40dcd8 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,6 @@ -### 4.0.0-alpha-008 - 06/2020 +### 4.0.0-alpha-009 - 06/2020 * WIP for [#705](https://github.com/fsprojects/fantomas/issues/705) +* FCS 36 ### 3.3.0 - 02/2020 diff --git a/paket.dependencies b/paket.dependencies index 25b65fe111..d4fab929d3 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -3,7 +3,7 @@ framework: netstandard2.0, netcoreapp3.1 storage: none nuget FSharp.Core -nuget FSharp.Compiler.Service 35.0.0 +nuget FSharp.Compiler.Service ~> 36.0 nuget FsUnit nuget FsCheck nuget Microsoft.NET.Test.Sdk 16.4.0 diff --git a/paket.lock b/paket.lock index 6802a9cc92..e7da1b0ad5 100644 --- a/paket.lock +++ b/paket.lock @@ -25,7 +25,7 @@ NUGET CommandLineParser (2.8) FsCheck (2.14) FSharp.Core (>= 4.2.3) - FSharp.Compiler.Service (35.0) + FSharp.Compiler.Service (36.0.1) FSharp.Core (>= 4.6.2) System.Buffers (>= 4.5) System.Collections.Immutable (>= 1.5) diff --git a/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj b/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj index ff5bb29c79..1f9c050fcc 100644 --- a/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj +++ b/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj @@ -4,7 +4,7 @@ netcoreapp3.1 false false - 4.0.0-alpha-008 + 4.0.0-alpha-009 FS0988 diff --git a/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj b/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj index 6e5cf5b3cf..84435fc6e5 100644 --- a/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj +++ b/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj @@ -4,7 +4,7 @@ netcoreapp3.1 fantomas True - 4.0.0-alpha-008 + 4.0.0-alpha-009 fantomas-tool diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index 3ddedf46dc..1a9cb4a58a 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -1,7 +1,7 @@ - 4.0.0-alpha-008 + 4.0.0-alpha-009 FS0988 netcoreapp3.1 diff --git a/src/Fantomas.Tests/FunctionDefinitionTests.fs b/src/Fantomas.Tests/FunctionDefinitionTests.fs index ce689278c9..0c7a845d67 100644 --- a/src/Fantomas.Tests/FunctionDefinitionTests.fs +++ b/src/Fantomas.Tests/FunctionDefinitionTests.fs @@ -356,7 +356,7 @@ let ``lambda with complex type``() = formatSourceString false """let x = fun ((u, v):(int*int)) -> 5""" config |> prepend newline |> should equal """ -let x = fun ((u, v): int * int) -> 5 +let x = fun ((u, v): (int * int)) -> 5 """ [] diff --git a/src/Fantomas.Tests/OperatorTests.fs b/src/Fantomas.Tests/OperatorTests.fs index d03f4c66f2..1c0c6319a0 100644 --- a/src/Fantomas.Tests/OperatorTests.fs +++ b/src/Fantomas.Tests/OperatorTests.fs @@ -443,4 +443,13 @@ async { | None -> printfn \"Function returned None!\" } \"\"\" -" \ No newline at end of file +" + +[] +let ``addition via function`` () = + formatSourceString false """let a = (+) 7 8 +""" config + |> prepend newline + |> should equal """ +let a = (+) 7 8 +""" diff --git a/src/Fantomas.Tests/SignatureTests.fs b/src/Fantomas.Tests/SignatureTests.fs index 5773f54b4d..3adece3d00 100644 --- a/src/Fantomas.Tests/SignatureTests.fs +++ b/src/Fantomas.Tests/SignatureTests.fs @@ -66,7 +66,7 @@ let ``should keep the string * string * string option type signature``() = """ config |> should equal """type DGML = | Node of string - | Link of string * string * string option + | Link of string * string * (string option) """ [] @@ -127,7 +127,7 @@ val GetHashCodeTainted : (Tainted<'T> -> int) when 'T : equality |> should equal """ module Tainted -val GetHashCodeTainted: Tainted<'T> -> int when 'T: equality +val GetHashCodeTainted: (Tainted<'T> -> int) when 'T: equality """ [] diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index a313815e42..9c5f441a5d 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -1309,6 +1309,23 @@ type VersionMismatchDuringDeserializationException(message : string, """ [] +let ``tuple typed abbreviation`` () = + formatSourceString false """type A = (int * int) +""" config + |> prepend newline + |> should equal """ +type A = (int * int) +""" + +[] +let ``function signature type abbreviation`` () = + formatSourceString false """type A = (int -> int -> int) +""" config + |> prepend newline + |> should equal """ +type A = (int -> int -> int) +""" + let ``type record declaration with attributes, 910`` () = formatSourceString false """type Commenter = { [] diff --git a/src/Fantomas/AstTransformer.fs b/src/Fantomas/AstTransformer.fs index 2e0308ecda..d8958ea004 100644 --- a/src/Fantomas/AstTransformer.fs +++ b/src/Fantomas/AstTransformer.fs @@ -1537,6 +1537,12 @@ module private Ast = Properties = p ["isStruct" ==> isStruct] FsAstNode = st Childs = List.map visitAnonRecordTypeField typeNames} + | SynType.Paren(innerType,range) -> + {Type = "SynType.Paren" + Range = r range + Properties = p [] + FsAstNode = st + Childs = [yield visitSynType innerType]} and visitSynConst(sc: SynConst) = sprintf "%A" sc diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 149adaecfc..0d8e2de768 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2362,7 +2362,7 @@ and genType astContext outerBracket t = | TFun(TTuple ts, t) -> sepOpenT +> loopTTupleList ts +> sepArrow +> loop t +> sepCloseT // Do similar for tuples after an arrow | TFun(t, TTuple ts) -> sepOpenT +> loop t +> sepArrow +> loopTTupleList ts +> sepCloseT - | TFuns ts -> sepOpenT +> col sepArrow ts loop +> sepCloseT + | TFuns ts -> col sepArrow ts loop | TApp(t, ts, isPostfix) -> let postForm = match ts with @@ -2373,7 +2373,7 @@ and genType astContext outerBracket t = ifElse isPostfix postForm (loop t +> genPrefixTypes astContext ts) | TLongIdentApp(t, s, ts) -> loop t -- sprintf ".%s" s +> genPrefixTypes astContext ts - | TTuple ts -> sepOpenT +> loopTTupleList ts +> sepCloseT + | TTuple ts -> loopTTupleList ts | TStructTuple ts -> !- "struct " +> sepOpenT +> loopTTupleList ts +> sepCloseT | TWithGlobalConstraints(TVar _, [TyparSubtypeOfType _ as tc]) -> genTypeConstraint astContext tc | TWithGlobalConstraints(TFuns ts, tcs) -> col sepArrow ts loop +> colPre (!- " when ") wordAnd tcs (genTypeConstraint astContext) @@ -2394,7 +2394,8 @@ and genType astContext outerBracket t = fun (ctx:Context) -> isShortExpression ctx.Config.MaxRecordWidth shortExpression longExpression ctx - + | TParen(innerT) -> + sepOpenT +> loop innerT +> sepCloseT | t -> failwithf "Unexpected type: %O" t and loopTTupleList = function diff --git a/src/Fantomas/Fantomas.fsproj b/src/Fantomas/Fantomas.fsproj index 8a8509469e..0db9e911c2 100644 --- a/src/Fantomas/Fantomas.fsproj +++ b/src/Fantomas/Fantomas.fsproj @@ -3,7 +3,7 @@ netstandard2.0 - 4.0.0-alpha-008 + 4.0.0-alpha-009 Source code formatter for F# diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index 27f0ad4c25..66c30a3814 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -99,8 +99,7 @@ let (|OpName|) (x : Identifier) = | Id(Ident s) | LongId(LongIdent s) -> DecompileOpName s -/// Operators in their declaration form -let (|OpNameFull|) (x : Identifier) = +let (|OpNameFullInPattern|) (x: Identifier) = let r = x.Ranges let s = x.Text let s' = DecompileOpName s @@ -109,6 +108,23 @@ let (|OpNameFull|) (x : Identifier) = if String.startsWithOrdinal "*" s' && s' <> "*" then sprintf "( %s )" s' else sprintf "(%s)" s' + else + match x with + | Id(Ident s) | LongId(LongIdent s) -> + DecompileOpName s + |> fun s -> (s, r) + + +/// Operators in their declaration form +let (|OpNameFull|) (x : Identifier) = + let r = x.Ranges + let s = x.Text + let s' = DecompileOpName s + + if IsActivePatternName s then + s + elif IsInfixOperator s || IsPrefixOperator s || IsTernaryOperator s || s = "op_Dynamic" then + s' else match x with | Id(Ident s) | LongId(LongIdent s) -> @@ -637,6 +653,7 @@ let (|Indexer|) = function | SynIndexerArg.Two(e1,e1FromEnd,e2,e2FromEnd,_,_) -> Pair((e1, e1FromEnd), (e2, e2FromEnd)) | SynIndexerArg.One(e,fromEnd,_) -> Single(e, fromEnd) +// hier ergens let (|OptVar|_|) = function | SynExpr.Ident(IdentOrKeyword(OpNameFull (s,r))) -> Some(s, false, r) @@ -981,13 +998,14 @@ let (|PatTyped|_|) = function Some(p, t) | _ -> None +// of hier let (|PatNamed|_|) = function - | SynPat.Named(p, IdentOrKeyword(OpNameFull (s,_)), _, ao, _) -> + | SynPat.Named(p, IdentOrKeyword(OpNameFullInPattern (s,_)), _, ao, _) -> Some(ao, p, s) | _ -> None let (|PatLongIdent|_|) = function - | SynPat.LongIdent(LongIdentWithDots.LongIdentWithDots(LongIdentOrKeyword(OpNameFull (s,_)), _), _, tpso, xs, ao, _) -> + | SynPat.LongIdent(LongIdentWithDots.LongIdentWithDots(LongIdentOrKeyword(OpNameFullInPattern (s,_)), _), _, tpso, xs, ao, _) -> match xs with | SynArgPats.Pats ps -> Some(ao, s, List.map (fun p -> (None, p)) ps, tpso) @@ -1249,6 +1267,9 @@ let (|TAnonRecord|_|) = function Some(isStruct, fields) | _ -> None +let (|TParen|_|) = function + | SynType.Paren(innerType, _) -> Some(innerType) + | _ -> None // Type parameter type SingleTyparConstraintKind = @@ -1284,7 +1305,7 @@ let (|MSMember|MSInterface|MSInherit|MSValField|MSNestedType|) = function | SynMemberSig.ValField(f, _) -> MSValField f | SynMemberSig.NestedType(tds, _) -> MSNestedType tds -let (|Val|) (ValSpfn(ats, IdentOrKeyword(OpNameFull (s,_)), tds, t, vi, isInline, _, px, ao, _, _)) = +let (|Val|) (ValSpfn(ats, IdentOrKeyword(OpNameFullInPattern (s,_)), tds, t, vi, isInline, _, px, ao, _, _)) = (ats, px, ao, s, t, vi, isInline, tds) // Misc