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

Don't consider cursor as trivia before of node. #3009

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Changelog

## Unreleased
## 6.3.0-alpha-004 - 2023-12-06

### Fixed
* Process is reserved keyword. [#2996](https://github.com/fsprojects/fantomas/issues/2996)
* Always yield list items on separate lines if a conditional is present. [#2972](https://github.com/fsprojects/fantomas/issues/2972)
* Trivia after mutable keyword is missing. [#3005](https://github.com/fsprojects/fantomas/issues/3005)
* Formatting can depend on cursor position. [#3007](https://github.com/fsprojects/fantomas/issues/3007)

### Changed
* Update FCS to 'Parser: recover on unfinished record decls, fix field ranges ', commit ee4a810ffe9e984e2ec8c55a9cb6d1c6631dd0b3 [#3006](https://github.com/fsprojects/fantomas/pull/3006)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Some common use cases include:
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<ServerGarbageCollection>true</ServerGarbageCollection>
<LangVersion>preview</LangVersion>
<OtherFlags>$(OtherFlags) --test:GraphBasedChecking --test:ParallelOptimization --test:ParallelIlxGen</OtherFlags>
<OtherFlags>$(OtherFlags) --test:GraphBasedChecking --test:ParallelOptimization --test:ParallelIlxGen --strict-indentation+</OtherFlags>
</PropertyGroup>

<!-- Versions -->
Expand Down
15 changes: 15 additions & 0 deletions src/Fantomas.Core.Tests/CursorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ type FSharpReformatCode(textControlManager: ITextControlManager) =
"""
(8, 19)
|> assertCursor (7, 15)

[<Test>]
let ``cursor is be consider as content before, 3007`` () =
nojaf marked this conversation as resolved.
Show resolved Hide resolved
let result =
formatWithCursor
"""pipeline "init" {
stage "restore-sln" {
parallel
run "dotnet tool restore"
}
}
"""
(4, 0)

result |> assertCursor (4, 0)
22 changes: 20 additions & 2 deletions src/Fantomas.Core/SyntaxOak.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,27 @@ type NodeBase(range: range) =
let nodesAfter = Queue<TriviaNode>(0)

member _.ContentBefore: TriviaNode seq = nodesBefore
member _.HasContentBefore = not (Seq.isEmpty nodesBefore)

member _.HasContentBefore =
nodesBefore
|> Seq.filter (fun tn ->
match tn.Content with
| Cursor -> false
| _ -> true)
|> Seq.isEmpty
|> not

member _.ContentAfter: TriviaNode seq = nodesAfter
member _.HasContentAfter = not (Seq.isEmpty nodesAfter)

member _.HasContentAfter =
nodesAfter
|> Seq.filter (fun tn ->
match tn.Content with
| Cursor -> false
| _ -> true)
|> Seq.isEmpty
|> not

member _.Range = range
member _.AddBefore triviaNode = nodesBefore.Enqueue triviaNode
member _.AddAfter triviaNode = nodesAfter.Enqueue triviaNode
Expand Down