Skip to content

Commit

Permalink
Fix 944 (#967)
Browse files Browse the repository at this point in the history
* Preserve the abstract keyword instead of the member for signature type members. Fixes #944

* Bumped alpha version and corrected unit test.

* Preserve both keywords
  • Loading branch information
nojaf committed Jul 14, 2020
1 parent a67f3a3 commit 3416b51
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 4.0.0-alpha-013 - 07/2020
### 4.0.0-alpha-014 - 07/2020
* WIP for [#705](https://github.com/fsprojects/fantomas/issues/705)
* FCS 36.0.3
* Replaced json configuration with .editorconfig
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-013</Version>
<Version>4.0.0-alpha-014</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-013</Version>
<Version>4.0.0-alpha-014</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-013</Version>
<Version>4.0.0-alpha-014</Version>
<NoWarn>FS0988</NoWarn>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
Expand Down
22 changes: 21 additions & 1 deletion src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ type internal Foo2 =
namespace Foo
type internal Foo2 =
member Bar<'k> : unit -> unit when 'k: comparison
abstract member Bar<'k> : unit -> unit when 'k: comparison
"""

[<Test>]
Expand Down Expand Up @@ -663,3 +663,23 @@ namespace B
type Foo =
member Item : 't -> unit when 't : comparison with set
"""

[<Test>]
let ``preserve abstract member in type, 944`` () =
formatSourceString true """
namespace Baz
type Foo =
abstract member Bar : Type
abstract Bar2 : Type
member Bar3 : Type
""" { config with SpaceBeforeColon = true }
|> prepend newline
|> should equal """
namespace Baz
type Foo =
abstract member Bar : Type
abstract Bar2 : Type
member Bar3 : Type
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ and genMemberFlagsForMemberBinding astContext (mf:MemberFlags) (rangeOfBindingAn
tn.ContentItself
|> Option.bind (fun tc ->
match tc with
| Keyword({ Content = ("override" | "default" | "member" | "abstract") as kw }) -> Some (!- (kw + " "))
| Keyword({ Content = ("override" | "default" | "member" | "abstract" | "abstract member") as kw }) -> Some (!- (kw + " "))
| _ -> None
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/Fantomas.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Version>4.0.0-alpha-013</Version>
<Version>4.0.0-alpha-014</Version>
<Description>Source code formatter for F#</Description>
</PropertyGroup>
<ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion src/Fantomas/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,25 @@ let private addTriviaToTriviaNode

| { Item = Keyword({ Content = keyword} as kw); Range = range } when (keyword = "override" || keyword = "default" || keyword = "member" || keyword = "abstract") ->
findMemberDefnMemberNodeOnLine triviaNodes range.StartLine
|> updateTriviaNode (fun tn -> tn.ContentItself <- Some (Keyword(kw))) triviaNodes
|> updateTriviaNode (fun tn ->
match tn.Type, tn.ContentItself with
| MainNode ("SynMemberSig.Member"), Some (Keyword ({ Content = existingKeywordContent } as token)) when existingKeywordContent =
"abstract"
&& keyword =
"member" ->
// Combine the two tokens to appear as one
let tokenInfo =
{ token.TokenInfo with
RightColumn = kw.TokenInfo.RightColumn }

let combinedKeyword =
{ token with
Content = "abstract member"
TokenInfo = tokenInfo }

tn.ContentItself <- Some(Keyword(combinedKeyword))
| _ -> tn.ContentItself <- Some(Keyword(kw))
) triviaNodes

| { Item = Keyword({ TokenInfo = {TokenName = tn}} as kw); Range = range } when (tn = "QMARK") ->
findConstNodeAfter triviaNodes range
Expand Down

0 comments on commit 3416b51

Please sign in to comment.