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 1 commit
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
20 changes: 20 additions & 0 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
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 Bar : Type
abstract Bar2 : Type
member Bar3 : Type
"""
12 changes: 11 additions & 1 deletion src/Fantomas/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,17 @@ 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 = existingKeyword })) when (existingKeyword = "abstract" && keyword = "member") ->
nojaf marked this conversation as resolved.
Show resolved Hide resolved
// edge case when for a signature file with:
// type Foo =
// abstract member Bar : Type
//
// here we don't want to override the abstract keyword
()
| _ -> tn.ContentItself <- Some (Keyword(kw))
) triviaNodes

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