Skip to content

Commit 4f2f9c1

Browse files
authored
Add cursor regression test. (#2899)
1 parent d8e7276 commit 4f2f9c1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Fantomas.Core.Tests/CursorTests.fs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,30 @@ let ``cursor inside a node between defines`` () =
4444
"""
4545
(3, 4)
4646
|> assertCursor (2, 0)
47+
48+
[<Test>]
49+
let ``cursor after try keyword`` () =
50+
formatWithCursor
51+
"""
52+
namespace JetBrains.ReSharper.Plugins.FSharp.Services.Formatter
53+
54+
[<CodeCleanupModule>]
55+
type FSharpReformatCode(textControlManager: ITextControlManager) =
56+
member x.Process(sourceFile, rangeMarker, _, _, _) =
57+
if isNotNull rangeMarker then
58+
try
59+
let range = ofDocumentRange rangeMarker.DocumentRange
60+
let formatted = fantomasHost.FormatSelection(filePath, range, text, settings, parsingOptions, newLineText)
61+
let offset = rangeMarker.DocumentRange.StartOffset.Offset
62+
let oldLength = rangeMarker.DocumentRange.Length
63+
let documentChange = DocumentChange(document, offset, oldLength, formatted, stamp, modificationSide)
64+
use _ = WriteLockCookie.Create()
65+
document.ChangeDocument(documentChange, TimeStamp.NextValue)
66+
sourceFile.GetPsiServices().Files.CommitAllDocuments()
67+
with _ -> ()
68+
else
69+
let textControl = textControlManager.VisibleTextControls |> Seq.find (fun c -> c.Document == document)
70+
cursorPosition = textControl.Caret.Position.Value.ToDocLineColumn();
71+
"""
72+
(8, 19)
73+
|> assertCursor (7, 15)

0 commit comments

Comments
 (0)