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

Fix 944 #967

Merged
merged 3 commits into from
Jul 14, 2020
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
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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my :P the actual content of the code looks fine to me, and I know it's entirely not my place to comment on code layout in a codebase I barely know, but a 120-space indent seems a bit much to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, but uh the thing is that I formatted it with Fantomas, so yeah 🙈.
I guess we can later use it as sample to improve.

"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