Skip to content

Commit

Permalink
Upgrade to FCS 40 (#1856)
Browse files Browse the repository at this point in the history
* Initial upgrade to FCS 40.

* Fix remaining unit tests.

* Remove AST workaround for Attributes.

* Update for SynTyparDecls, SynPat.As and ParsedHashDirectiveArgument.

* Re-enable ignored tests.

* Update to FCS 40.0.1-preview.21366.4
  • Loading branch information
nojaf committed Aug 11, 2021
1 parent 383b729 commit ac0fa7b
Show file tree
Hide file tree
Showing 19 changed files with 694 additions and 681 deletions.
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ source https://api.nuget.org/v3/index.json
framework: netstandard2.0, net5.0, netcoreapp3.1
storage: none

nuget FSharp.Core
nuget FSharp.Compiler.Service ~> 39.0
nuget FSharp.Core 5.0.3-beta.21352.5
nuget FSharp.Compiler.Service 40.0.1-preview.21352.5
nuget FsUnit
nuget FsCheck
nuget Microsoft.NET.Test.Sdk 16.9.1
Expand Down
39 changes: 22 additions & 17 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ NUGET
editorconfig (0.12.2)
FsCheck (2.14.3)
FSharp.Core (>= 4.2.3)
FSharp.Compiler.Service (39.0)
FSharp.Core (5.0.1)
Microsoft.Build.Framework (>= 16.6)
Microsoft.Build.Tasks.Core (>= 16.6)
Microsoft.Build.Utilities.Core (>= 16.6)
FSharp.Compiler.Service (40.0.1-preview.21352.5)
FSharp.Core (5.0.3-beta.21352.5)
Microsoft.Build.Framework (>= 16.9)
Microsoft.Build.Tasks.Core (>= 16.9)
Microsoft.Build.Utilities.Core (>= 16.9)
System.Buffers (>= 4.5.1)
System.Collections.Immutable (>= 5.0)
System.Diagnostics.Process (>= 4.3)
Expand All @@ -44,6 +44,7 @@ NUGET
System.Reflection.Metadata (>= 5.0)
System.Reflection.TypeExtensions (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.CompilerServices.Unsafe (>= 5.0)
System.Runtime.InteropServices (>= 4.3)
System.Runtime.Loader (>= 4.3)
System.Security.Claims (>= 4.3)
Expand All @@ -52,34 +53,35 @@ NUGET
System.Threading.Tasks.Parallel (>= 4.3)
System.Threading.Thread (>= 4.3)
System.Threading.ThreadPool (>= 4.3)
FSharp.Core (5.0.1)
FSharp.Core (5.0.3-beta.21352.5)
FsUnit (4.0.2)
FSharp.Core (>= 4.3.4)
NETStandard.Library (>= 2.0.3)
NUnit (>= 3.12 < 4.0)
Iced (1.7)
MAB.DotIgnore (3.0.2)
NETStandard.Library (>= 1.6.1)
Microsoft.Build.Framework (16.8)
Microsoft.Build.Framework (16.10)
System.Security.Permissions (>= 4.7)
Microsoft.Build.Tasks.Core (16.8)
Microsoft.Build.Framework (>= 16.8)
Microsoft.Build.Utilities.Core (>= 16.8)
Microsoft.Build.Tasks.Core (16.10)
Microsoft.Build.Framework (>= 16.10)
Microsoft.Build.Utilities.Core (>= 16.10)
Microsoft.NET.StringTools (>= 1.0)
Microsoft.Win32.Registry (>= 4.3)
System.CodeDom (>= 4.4)
System.Collections.Immutable (>= 1.5)
System.Collections.Immutable (>= 5.0)
System.Reflection.Metadata (>= 1.6)
System.Reflection.TypeExtensions (>= 4.1)
System.Resources.Extensions (>= 4.6)
System.Runtime.InteropServices (>= 4.3)
System.Security.Cryptography.Pkcs (>= 4.7)
System.Security.Cryptography.Xml (>= 4.7)
System.Security.Permissions (>= 4.7)
System.Threading.Tasks.Dataflow (>= 4.9)
Microsoft.Build.Utilities.Core (16.8)
Microsoft.Build.Framework (>= 16.8)
Microsoft.Build.Utilities.Core (16.10)
Microsoft.Build.Framework (>= 16.10)
Microsoft.NET.StringTools (>= 1.0)
Microsoft.Win32.Registry (>= 4.3)
System.Collections.Immutable (>= 1.5)
System.Collections.Immutable (>= 5.0)
System.Configuration.ConfigurationManager (>= 4.7)
System.Security.Permissions (>= 4.7)
System.Text.Encoding.CodePages (>= 4.0.1)
Microsoft.CodeAnalysis.Analyzers (3.0)
Expand All @@ -99,6 +101,9 @@ NUGET
Microsoft.Diagnostics.Tracing.TraceEvent (2.0.56)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2)
Microsoft.DotNet.PlatformAbstractions (3.1.4)
Microsoft.NET.StringTools (1.0)
System.Memory (>= 4.5.4)
System.Runtime.CompilerServices.Unsafe (>= 5.0)
Microsoft.NET.Test.Sdk (16.9.1)
Microsoft.CodeCoverage (>= 16.9.1) - restriction: || (== net5.0) (== netcoreapp3.1) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.TestPlatform.TestHost (>= 16.9.1) - restriction: || (== net5.0) (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp1.0))
Expand Down Expand Up @@ -437,7 +442,7 @@ NUGET
System.Runtime (4.3.1)
Microsoft.NETCore.Platforms (>= 1.1.1)
Microsoft.NETCore.Targets (>= 1.1.3)
System.Runtime.CompilerServices.Unsafe (4.7)
System.Runtime.CompilerServices.Unsafe (5.0)
System.Runtime.Extensions (4.3.1)
Microsoft.NETCore.Platforms (>= 1.1.1)
Microsoft.NETCore.Targets (>= 1.1.3)
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Benchmarks/Runners.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Fantomas.Benchmarks.Runners

open BenchmarkDotNet.Attributes
open System.IO
open FSharp.Compiler.SourceCodeServices
open BenchmarkDotNet.Attributes
open FSharp.Compiler.CodeAnalysis
open Fantomas
open Fantomas.Extras

Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Extras/FakeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Fantomas.Extras.FakeHelpers

open System
open System.IO
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.CodeAnalysis
open Fantomas
open Fantomas.FormatConfig
open Fantomas.Extras
Expand Down
42 changes: 42 additions & 0 deletions src/Fantomas.Tests/AttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,45 @@ module Foo =
[<DllImport("Kernel32.dll", SetLastError = true)>]
extern bool GetFileInformationByHandleEx(IntPtr hFile, FILE_INFO_BY_HANDLE_CLASS infoClass, [<Out>] FILE_NAME_INFO& info, uint32 dwBufferSize)
"""

[<Test>]
let ``comment after attribute before let binding with return type`` () =
formatSourceString
false
"""
[<Foo>]
// bar
let add (a: int) ( b : int) : int = a + b
"""
config
|> prepend newline
|> should
equal
"""
[<Foo>]
// bar
let add (a: int) (b: int) : int = a + b
"""

[<Test>]
let ``comment after attribute before value binding with return type`` () =
formatSourceString
false
"""
[<Foo>]
// bar
// bar again, cuz why not
let x: int = 99
"""
config
|> prepend newline
|> should
equal
"""
[<Foo>]
// bar
// bar again, cuz why not
let x: int = 99
"""
24 changes: 12 additions & 12 deletions src/Fantomas.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module Fantomas.Tests.TestHelper

open FsUnit
open System
open System.IO
open NUnit.Framework
open FsCheck
open FsUnit
open FSharp.Compiler.Text
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Syntax
open FSharp.Compiler.Xml
open Fantomas.FormatConfig
open Fantomas
open Fantomas.Extras
open FSharp.Compiler.Text
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.XmlDoc
open NUnit.Framework
open FsCheck
open System.IO

[<assembly: Parallelizable(ParallelScope.All)>]
do ()
Expand Down Expand Up @@ -41,7 +41,7 @@ let private isValidAndHasNoWarnings fileName source parsingOptions =
let! untypedRes = sharedChecker.Value.ParseFile(fileName, sourceText, parsingOptionsWithDefines)

let errors =
untypedRes.Errors
untypedRes.Diagnostics
|> Array.filter (fun e -> not (List.contains e.Message safeToIgnoreWarnings))
// FSharpErrorInfo contains both Errors and Warnings
// https://fsharp.github.io/FSharp.Compiler.Service/reference/fsharp-compiler-sourcecodeservices-fsharperrorinfo.html
Expand Down Expand Up @@ -206,7 +206,7 @@ let toSynExprs (Input s) =
[],
[ SynModuleOrNamespace (_,
false,
AnonModule,
SynModuleOrNamespaceKind.AnonModule,
exprs,
_,
_,
Expand Down Expand Up @@ -246,8 +246,8 @@ let fromSynExpr expr =
[ SynModuleOrNamespace(
[ ident ],
false,
AnonModule,
[ SynModuleDecl.DoExpr(NoDebugPointAtDoBinding, expr, zero) ],
SynModuleOrNamespaceKind.AnonModule,
[ SynModuleDecl.DoExpr(DebugPointAtBinding.NoneAtDo, expr, zero) ],
PreXmlDoc.Empty,
[],
None,
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/TokenParserTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let private mkRange: MkRange =
fun (sl, sc) (el, ec) ->
FSharp.Compiler.Text.Range.mkRange
"TokenParserTests"
(FSharp.Compiler.Text.Pos.mkPos sl sc)
(FSharp.Compiler.Text.Pos.mkPos el ec)
(FSharp.Compiler.Text.Position.mkPos sl sc)
(FSharp.Compiler.Text.Position.mkPos el ec)

let private getTriviaFromTokens = getTriviaFromTokens mkRange
let private getTriviaNodesFromTokens = getTriviaNodesFromTokens mkRange
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/TriviaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ let private collectTrivia =
(fun (sl, sc) (el, ec) ->
FSharp.Compiler.Text.Range.mkRange
"TriviaTests"
(FSharp.Compiler.Text.Pos.mkPos sl sc)
(FSharp.Compiler.Text.Pos.mkPos el ec))
(FSharp.Compiler.Text.Position.mkPos sl sc)
(FSharp.Compiler.Text.Position.mkPos el ec))

let private toTrivia source =
let astWithDefines = parse false source |> Array.toList
Expand Down
45 changes: 38 additions & 7 deletions src/Fantomas/AstExtensions.fs
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
module Fantomas.AstExtensions

open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.Syntax
open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range

type SynTypeDefnSig with
/// Combines the range of type name and the body.
member this.FullRange: Range =
match this with
| SynTypeDefnSig.TypeDefnSig (comp, _, _, r) -> mkRange r.FileName comp.Range.Start r.End

let longIdentFullRange (li: LongIdent) : Range =
match li with
| [] -> range.Zero
| h :: _ -> unionRanges h.idRange (List.last li).idRange

let private hasLinesBetweenAttributesAndFirstNode (attributes: SynAttributes) (firstNodeRange: Range) : Range option =
let fileName = firstNodeRange.FileName

List.tryLast attributes
|> Option.bind
(fun lastAttribute ->
if lastAttribute.Range.EndLine + 1 < firstNodeRange.StartLine
&& firstNodeRange.Start.Column > 0 then
let pos =
Position.mkPos firstNodeRange.StartLine 0

mkRange fileName pos pos |> Some
else
None)

type SynBinding with
/// Construct an artificial range after the attributes and before the head pattern.
/// This is to detect newline or comment trivia in that exact location.
member this.AfterAttributesBeforeHeadPattern: Range option =
match this with
| SynBinding(attributes = []) -> None
| SynBinding (attributes = attrs; headPat = pat) -> hasLinesBetweenAttributesAndFirstNode attrs pat.Range

type SynTypeDefn with
member this.AfterAttributesBeforeComponentInfo: Range option =
match this with
| SynTypeDefn(typeInfo = SynComponentInfo(attributes = [])) -> None
| SynTypeDefn(typeInfo = SynComponentInfo (attributes = attrs; range = compRange)) ->
hasLinesBetweenAttributesAndFirstNode attrs compRange

type SynField with
member this.AfterAttributesBeforeIdentifier: Range option =
match this with
| SynField(attributes = []) -> None
| SynField (attributes = _ :: _; idOpt = None) -> None
| SynField (attributes = attrs; idOpt = Some ident) -> hasLinesBetweenAttributesAndFirstNode attrs ident.idRange
Loading

0 comments on commit ac0fa7b

Please sign in to comment.