Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [5.2.0-alpha-009] - 2022-12-29

### Fixes
* ifdef removed when used on inline keyword in function. [#2017](https://github.com/fsprojects/fantomas/issues/2017)

### Changed
* Update FCS to 'Include inline in trivia', commit e30d14cb46f290050ac8e2bbea5e9b804b97bdde

## [5.2.0-alpha-008] - 2022-12-28

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Some common use cases include:

<!-- Versions -->
<PropertyGroup>
<FCSCommitHash>70499ce779ffeeda0a1d96761a184981baf762ef</FCSCommitHash>
<FCSCommitHash>e30d14cb46f290050ac8e2bbea5e9b804b97bdde</FCSCommitHash>
<StreamJsonRpcVersion>2.8.28</StreamJsonRpcVersion>
<FSharpCoreVersion>6.0.1</FSharpCoreVersion>
</PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ pipeline "Init" {
"src/Compiler/Utilities/range.fsi"
"src/Compiler/Utilities/range.fs"
"src/Compiler/Facilities/UtilsStrings.txt"
"src/Compiler/Facilities/Logger.fsi"
"src/Compiler/Facilities/Logger.fs"
"src/Compiler/Facilities/LanguageFeatures.fsi"
"src/Compiler/Facilities/LanguageFeatures.fs"
"src/Compiler/Facilities/DiagnosticOptions.fsi"
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ let a =
None,
MultipleTextsNode([ stn "let" ], zeroRange),
false,
false,
None,
None,
Choice1Of2(IdentListNode([ IdentifierOrDot.Ident(stn "a") ], zeroRange)),
None,
Expand Down Expand Up @@ -324,7 +324,7 @@ let b = 2
None,
MultipleTextsNode([ stn "let" ], zeroRange),
false,
false,
None,
None,
Choice1Of2(IdentListNode([ IdentifierOrDot.Ident(stn name) ], zeroRange)),
None,
Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas.Core.Tests/FangornTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ let ``avoid stack-overflow in long array/list, 2485`` () =
) ],
(false, false),
{ ConditionalDirectives = []
CodeComments = [] }
CodeComments = [] },
Set.empty
)
)

Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="TypeAnnotationTests.fs" />
<Compile Include="BaseConstructorTests.fs" />
<Compile Include="DallasTests.fs" />
<Compile Include="InlineTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />
Expand Down
85 changes: 85 additions & 0 deletions src/Fantomas.Core.Tests/InlineTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module Fantomas.Core.Tests.InlineTests

open NUnit.Framework
open FsUnit
open Fantomas.Core.Tests.TestHelper

[<Test>]
let ``trivia around inline keyword, 2017`` () =
formatSourceString
false
"""
let
#if !DEBUG
inline
#endif
map f ar = Async.map (Result.map f) ar
"""
config
|> prepend newline
|> should
equal
"""
let
#if !DEBUG
inline
#endif
map
f
ar
=
Async.map (Result.map f) ar
"""

[<Test>]
let ``inline in plain member`` () =
formatSourceString
false
"""
type X =
member inline x.Y () = ()
"""
config
|> prepend newline
|> should
equal
"""
type X =
member inline x.Y() = ()
"""

[<Test>]
let ``inline in get/set member`` () =
formatSourceString
false
"""
type X =
member inline x.Y
with inline get () = 4
and inline set y = ()
"""
config
|> prepend newline
|> should
equal
"""
type X =
member inline x.Y
with inline get () = 4
and inline set y = ()
"""

[<Test>]
let ``inline in val`` () =
formatSourceString
true
"""
val inline meh: int -> int
"""
config
|> prepend newline
|> should
equal
"""
val inline meh: int -> int
"""
3 changes: 2 additions & 1 deletion src/Fantomas.Core.Tests/SynLongIdentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ let ``backticks can be added from AST only scenarios`` () =
) ],
(true, false),
{ ConditionalDirectives = []
CodeComments = [] }
CodeComments = [] },
Set.empty
)
)

Expand Down
33 changes: 25 additions & 8 deletions src/Fantomas.Core/CodePrinter2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2645,7 +2645,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =

let afterLetKeyword =
ifElse b.IsMutable (!- "mutable ") sepNone
+> ifElse b.IsInline (!- "inline ") sepNone
+> genInlineOpt b.Inline
+> genAccessOpt b.Accessibility

let genFunctionName =
Expand Down Expand Up @@ -2710,7 +2710,17 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
| _ -> col sepNln b.Parameters genPat, false
| _ -> col sepNln b.Parameters genPat, false

(afterLetKeyword
let hasTriviaAfterLeadingKeyword =
let beforeInline =
match b.Inline with
| None -> false
| Some n -> (n :> Node).HasContentBefore

let beforeIdentifier = (functionName :> Node).HasContentBefore
beforeInline || beforeIdentifier

(onlyIf hasTriviaAfterLeadingKeyword indent
+> afterLetKeyword
+> sepSpace
+> genFunctionName
+> indent
Expand All @@ -2724,7 +2734,8 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
sepNln +> genSingleTextNode b.Equals
else
sepSpace +> genSingleTextNode b.Equals)
+> unindent)
+> unindent
+> onlyIf hasTriviaAfterLeadingKeyword unindent)
ctx

expressionFitsOnRestOfLine short long
Expand Down Expand Up @@ -2759,7 +2770,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
let afterLetKeyword =
genAccessOpt b.Accessibility
+> ifElse b.IsMutable (!- "mutable ") sepNone
+> ifElse b.IsInline (!- "inline ") sepNone
+> genInlineOpt b.Inline

let genDestructedTuples =
expressionFitsOnRestOfLine (genPat pat) (sepOpenT +> genPat pat +> sepCloseT)
Expand Down Expand Up @@ -2794,7 +2805,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =

let afterLetKeyword =
ifElse b.IsMutable (!- "mutable ") sepNone
+> ifElse b.IsInline (!- "inline ") sepNone
+> genInlineOpt b.Inline
+> genAccessOpt b.Accessibility

let genValueName =
Expand Down Expand Up @@ -3466,6 +3477,11 @@ let genTypeAndParam (genTypeName: Context -> Context) (tds: TyparDecls option) =
| Some(TyparDecls.PrefixList _) -> optSingle (fun tds -> genTyparDecls tds +> sepSpace) tds +> genTypeName
| Some(TyparDecls.SinglePrefix singlePrefixNode) -> genTyparDecl true singlePrefixNode +> sepSpace +> genTypeName

let genInlineOpt (inlineNode: SingleTextNode option) =
match inlineNode with
| None -> sepNone
| Some inlineNode -> genSingleTextNodeWithSpaceSuffix sepSpace inlineNode

let genVal (node: ValNode) (optGetSet: MultipleTextsNode option) =
let genOptExpr =
match node.Equals, node.Expr with
Expand All @@ -3475,7 +3491,7 @@ let genVal (node: ValNode) (optGetSet: MultipleTextsNode option) =
genXml node.XmlDoc
+> genAttributes node.Attributes
+> optSingle (fun lk -> genMultipleTextsNode lk +> sepSpace) node.LeadingKeyword
+> onlyIf node.IsInline (!- "inline ")
+> genInlineOpt node.Inline
+> onlyIf node.IsMutable (!- "mutable ")
+> genAccessOpt node.Accessibility
+> genTypeAndParam (genSingleTextNode node.Identifier) node.TypeParams
Expand Down Expand Up @@ -3563,7 +3579,8 @@ let genMemberDefn (md: MemberDefn) =
|> genNode (MemberDefn.Node md)
| MemberDefn.PropertyGetSet node ->
let genProperty (node: PropertyGetSetBindingNode) =
genAccessOpt node.Accessibility
genInlineOpt node.Inline
+> genAccessOpt node.Accessibility
+> genSingleTextNode node.LeadingKeyword
+> sepSpace
+> col sepSpace node.Parameters genPat
Expand All @@ -3576,7 +3593,7 @@ let genMemberDefn (md: MemberDefn) =
+> genAttributes node.Attributes
+> genMultipleTextsNode node.LeadingKeyword
+> sepSpace
+> onlyIf node.IsInline (!- "inline ")
+> genInlineOpt node.Inline
+> genAccessOpt node.Accessibility
+> genIdentListNode node.MemberName
+> indent
Expand Down
30 changes: 16 additions & 14 deletions src/Fantomas.Core/Fangorn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ let (|OperatorWithStar|_|) (si: SynIdent) =

let mkBinding
(creationAide: CreationAide)
(SynBinding(_, _, isInline, isMutable, attributes, xmlDoc, _, pat, returnInfo, expr, _, _, trivia))
(SynBinding(_, _, _, isMutable, attributes, xmlDoc, _, pat, returnInfo, expr, _, _, trivia))
=
let mkFunctionName (sli: SynLongIdent) : IdentListNode =
match sli.IdentsWithTrivia with
Expand Down Expand Up @@ -1570,7 +1570,7 @@ let mkBinding
mkAttributes creationAide attributes,
mkSynLeadingKeyword trivia.LeadingKeyword,
isMutable,
isInline,
Option.map (stn "inline") trivia.InlineKeyword,
mkSynAccess ao,
functionName,
genericParameters,
Expand Down Expand Up @@ -2323,7 +2323,8 @@ let mkPropertyGetSetBinding
headPat = SynPat.LongIdent(extraId = Some extraIdent; accessibility = ao; argPats = SynArgPats.Pats ps)
returnInfo = returnInfo
expr = expr
trivia = { EqualsRange = Some mEq }) ->
trivia = { EqualsRange = Some mEq
InlineKeyword = inlineKw }) ->
let e = parseExpressionInSynBinding returnInfo expr
let returnTypeNode = mkBindingReturnInfo creationAide returnInfo

Expand All @@ -2346,6 +2347,7 @@ let mkPropertyGetSetBinding
let range = unionRanges extraIdent.idRange e.Range

PropertyGetSetBindingNode(
Option.map (stn "inline") inlineKw,
mkSynAccess ao,
leadingKeyword,
pats,
Expand Down Expand Up @@ -2509,11 +2511,11 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =
|> MemberDefn.AbstractSlot
| SynMemberDefn.GetSetMember(Some(SynBinding(
accessibility = ao
isInline = isInline
attributes = ats
xmlDoc = px
headPat = SynPat.LongIdent(longDotId = memberName)
trivia = { LeadingKeyword = lk }) as getBinding),
trivia = { LeadingKeyword = lk
InlineKeyword = inlineKw }) as getBinding),
Some setBinding,
_,
{ GetKeyword = Some getKeyword
Expand All @@ -2532,7 +2534,7 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =
mkXmlDoc px,
mkAttributes creationAide ats,
mkSynLeadingKeyword lk,
isInline,
Option.map (stn "inline") inlineKw,
mkSynAccess ao,
mkSynLongIdent memberName,
stn "with" withKeyword,
Expand All @@ -2545,22 +2547,22 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =
| SynMemberDefn.GetSetMember(None,
Some(SynBinding(
accessibility = ao
isInline = isInline
attributes = ats
xmlDoc = px
headPat = SynPat.LongIdent(longDotId = memberName)
trivia = { LeadingKeyword = lk }) as binding),
trivia = { LeadingKeyword = lk
InlineKeyword = inlineKw }) as binding),
_,
{ WithKeyword = withKeyword
GetKeyword = getKeyword
SetKeyword = setKeyword })
| SynMemberDefn.GetSetMember(Some(SynBinding(
accessibility = ao
isInline = isInline
attributes = ats
xmlDoc = px
headPat = SynPat.LongIdent(longDotId = memberName)
trivia = { LeadingKeyword = lk }) as binding),
trivia = { LeadingKeyword = lk
InlineKeyword = inlineKw }) as binding),
None,
_,
{ WithKeyword = withKeyword
Expand All @@ -2576,7 +2578,7 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =
mkXmlDoc px,
mkAttributes creationAide ats,
mkSynLeadingKeyword lk,
isInline,
Option.map (stn "inline") inlineKw,
mkSynAccess ao,
mkSynLongIdent memberName,
stn "with" withKeyword,
Expand All @@ -2594,7 +2596,7 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =
mkXmlDoc px,
mkAttributes creationAide ats,
mkSynLeadingKeyword lk,
isInline,
Option.map (stn "inline") inlineKw,
mkSynAccess ao,
mkSynLongIdent memberName,
stn "with" withKeyword,
Expand All @@ -2609,7 +2611,7 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =

let mkVal
(creationAide: CreationAide)
(SynValSig(ats, synIdent, vtd, t, _vi, isInline, isMutable, px, ao, eo, range, trivia))
(SynValSig(ats, synIdent, vtd, t, _vi, _isInline, isMutable, px, ao, eo, range, trivia))
: ValNode =
let lk =
match trivia.LeadingKeyword with
Expand All @@ -2620,7 +2622,7 @@ let mkVal
mkXmlDoc px,
mkAttributes creationAide ats,
lk,
isInline,
Option.map (stn "inline") trivia.InlineKeyword,
isMutable,
mkSynAccess ao,
mkSynIdent synIdent,
Expand Down
Loading