Skip to content

Commit

Permalink
Fix restoring line comment above static member in signature file. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Apr 15, 2020
1 parent fd58841 commit 9cb5a66
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,37 @@ type T =
type T with
member Foo: int
"""
"""

[<Test>]
let ``comment above static member, 680`` () =
formatSourceString true """
namespace Fantomas
open Fantomas.FormatConfig
open Fantomas.SourceOrigin
open FSharp.Compiler.Ast
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
[<Sealed>]
type CodeFormatter =
/// Parse a source string using given config
static member ParseAsync : fileName:string * source:SourceOrigin * parsingOptions: FSharpParsingOptions * checker:FSharpChecker -> Async<(ParsedInput * string list) array>
""" config
|> prepend newline
|> should equal """
namespace Fantomas
open Fantomas.FormatConfig
open Fantomas.SourceOrigin
open FSharp.Compiler.Ast
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
[<Sealed>]
type CodeFormatter =
/// Parse a source string using given config
static member ParseAsync: fileName:string * source:SourceOrigin * parsingOptions:FSharpParsingOptions * checker:FSharpChecker
-> Async<(ParsedInput * string list) array>
"""
10 changes: 9 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,18 @@ and genSigModuleDeclList astContext node =
| [x] -> genSigModuleDecl astContext x

| SigOpenL(xs, ys) ->
let sepXsAndYs =
match List.tryHead ys with
| Some hs ->
let attrs = getRangesFromAttributesFromSynModuleSigDeclaration hs
sepNln +> sepNlnConsideringTriviaContentBeforeWithAttributes hs.Range attrs +> dumpAndContinue
| None ->
rep 2 sepNln

fun ctx ->
match ys with
| [] -> col sepNln xs (genSigModuleDecl astContext) ctx
| _ -> (col sepNln xs (genSigModuleDecl astContext) +> rep 2 sepNln +> genSigModuleDeclList astContext ys) ctx
| _ -> (col sepNln xs (genSigModuleDecl astContext) +> sepXsAndYs +> genSigModuleDeclList astContext ys) ctx

| SigHashDirectiveL(xs, ys) ->
match ys with
Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,8 @@ let getRangesFromAttributesFromModuleDeclaration (mdl: SynModuleDecl) =

let getRangesFromAttributesFromSynModuleSigDeclaration (sdl: SynModuleSigDecl) =
match sdl with
| SynModuleSigDecl.NestedModule((SynComponentInfo.ComponentInfo(attrs, _,_,_,_,_,_,_)), _,_,_) ->
| SynModuleSigDecl.NestedModule((SynComponentInfo.ComponentInfo(attrs, _,_,_,_,_,_,_)), _,_,_)
| SynModuleSigDecl.Types (SynTypeDefnSig.TypeDefnSig(SynComponentInfo.ComponentInfo(attrs, _,_,_,_,_,_,_),_,_,_)::_,_) ->
collectAttributesRanges attrs
| _ -> Seq.empty
|> Seq.toList
Expand Down
2 changes: 2 additions & 0 deletions src/Fantomas/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ let filterNodes nodes =
"SynModuleOrNamespaceSig.DeclaredNamespace"
"SynExpr.LetOrUse"
"SynTypeDefnRepr.ObjectModel"
"TypeDefnSig"
"SynTypeDefnSigRepr.ObjectModel"
]
nodes |> List.filter (fun (n: Node) -> not (Set.contains n.Type filterOutNodeTypes))

Expand Down

0 comments on commit 9cb5a66

Please sign in to comment.