Skip to content

Commit

Permalink
Update to FCS36 (and the SynType.Paren AST node :horror:) (fsprojects…
Browse files Browse the repository at this point in the history
…#899)

* add support for syntype.paren ast node

* naieve addition of parens to the syntype.paren rendering

* WIP meh

* Processed remaining FCS 36 changes.

* Update to alpha-009

Co-authored-by: nojaf <florian.verdonck@outlook.com>
  • Loading branch information
baronfel and nojaf committed Jun 12, 2020
1 parent 09c842e commit 11370c3
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 19 deletions.
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<Version>4.0.0-alpha-008</Version>
<Version>4.0.0-alpha-009</Version>
<NoWarn>FS0988</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ToolCommandName>fantomas</ToolCommandName>
<PackAsTool>True</PackAsTool>
<Version>4.0.0-alpha-008</Version>
<Version>4.0.0-alpha-009</Version>
<AssemblyName>fantomas-tool</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\netfx.props" />
<PropertyGroup>
<Version>4.0.0-alpha-008</Version>
<Version>4.0.0-alpha-009</Version>
<NoWarn>FS0988</NoWarn>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

[<Test>]
Expand Down
11 changes: 10 additions & 1 deletion src/Fantomas.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,13 @@ async {
| None -> printfn \"Function returned None!\"
}
\"\"\"
"
"
[<Test>]
let ``addition via function`` () =
formatSourceString false """let a = (+) 7 8
""" config
|> prepend newline
|> should equal """
let a = (+) 7 8
"""
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""

[<Test>]
Expand Down Expand Up @@ -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
"""

[<Test>]
Expand Down
17 changes: 17 additions & 0 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,23 @@ type VersionMismatchDuringDeserializationException(message : string,
"""

[<Test>]
let ``tuple typed abbreviation`` () =
formatSourceString false """type A = (int * int)
""" config
|> prepend newline
|> should equal """
type A = (int * int)
"""

[<Test>]
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 =
{ [<JsonProperty("display_name")>]
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas/AstTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/Fantomas.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\netfx.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>4.0.0-alpha-008</Version>
<Version>4.0.0-alpha-009</Version>
<Description>Source code formatter for F#</Description>
</PropertyGroup>
<ItemGroup>
Expand Down
31 changes: 26 additions & 5 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) ->
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1249,6 +1267,9 @@ let (|TAnonRecord|_|) = function
Some(isStruct, fields)
| _ -> None

let (|TParen|_|) = function
| SynType.Paren(innerType, _) -> Some(innerType)
| _ -> None
// Type parameter

type SingleTyparConstraintKind =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 11370c3

Please sign in to comment.