Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print trivia for ident of ValSpfn. #1568

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,3 +1325,30 @@ type 'a Bar =
///
| Quux
"""

[<Test>]
let ``comment between attribute and val, 1561`` () =
formatSourceString
true
"""
namespace Baz

module Bar =

[<Obsolete "">]
///
val f : unit -> unit
"""
config
|> prepend newline
|> should
equal
"""
namespace Baz

module Bar =

[<Obsolete "">]
///
val f : unit -> unit
"""
3 changes: 2 additions & 1 deletion src/Fantomas/AstTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,9 @@ module private Ast =

and visitSynValSig (svs: SynValSig) : TriviaNodeAssigner list =
match svs with
| ValSpfn (attrs, _, explicitValDecls, synType, arity, _, _, _, _, expr, range) ->
| ValSpfn (attrs, ident, explicitValDecls, synType, arity, _, _, _, _, expr, range) ->
[ yield mkNode ValSpfn_ range
yield visitIdent ident
yield! (visitSynAttributeLists range attrs)
yield! visitSynValTyparDecls explicitValDecls
yield! visitSynType synType
Expand Down
18 changes: 10 additions & 8 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ and genMemberFlagsForMemberBinding astContext (mf: MemberFlags) (rangeOfBindingA
|> Option.defaultValue (!- "override ")
<| ctx

and genVal astContext (Val (ats, px, ao, s, t, vi, isInline, _) as node) =
and genVal astContext (Val (ats, px, ao, s, identRange, t, vi, isInline, _) as node) =
let range, synValTyparDecls =
match node with
| ValSpfn (_, _, synValTyparDecls, _, _, _, _, _, _, _, range) -> range, synValTyparDecls
Expand All @@ -874,12 +874,14 @@ and genVal astContext (Val (ats, px, ao, s, t, vi, isInline, _) as node) =

let (FunType namedArgs) = (t, vi)

genPreXmlDoc px +> genAttributes astContext ats
-- "val "
+> opt sepSpace ao genAccess
+> onlyIf isInline (!- "inline ")
-- s
+> genericParams
genPreXmlDoc px
+> genAttributes astContext ats
+> (!- "val "
+> opt sepSpace ao genAccess
+> onlyIf isInline (!- "inline ")
-- s
+> genericParams
|> genTriviaFor Ident_ identRange)
+> sepColonWithSpacesFixed
+> ifElse
(List.isNotEmpty namedArgs)
Expand Down Expand Up @@ -3898,7 +3900,7 @@ and genMemberSig astContext node =
| SynMemberSig.NestedType (_, r) -> r, SynMemberSig_NestedType

match node with
| MSMember (Val (ats, px, ao, s, t, vi, isInline, ValTyparDecls (tds, _, tcs)), mf) ->
| MSMember (Val (ats, px, ao, s, _, t, vi, isInline, ValTyparDecls (tds, _, tcs)), mf) ->
let (FunType namedArgs) = (t, vi)

let isFunctionProperty =
Expand Down
6 changes: 4 additions & 2 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,8 +1505,10 @@ let (|MSMember|MSInterface|MSInherit|MSValField|MSNestedType|) =
| SynMemberSig.ValField (f, _) -> MSValField f
| SynMemberSig.NestedType (tds, _) -> MSNestedType tds

let (|Val|) (ValSpfn (ats, IdentOrKeyword (OpNameFullInPattern (s, _)), tds, t, vi, isInline, _, px, ao, _, _)) =
(ats, px, ao, s, t, vi, isInline, tds)
let (|Val|)
(ValSpfn (ats, ((IdentOrKeyword (OpNameFullInPattern (s, _)) as ident)), tds, t, vi, isInline, _, px, ao, _, _))
=
(ats, px, ao, s, ident.idRange, t, vi, isInline, tds)

// Misc

Expand Down