Skip to content

Commit

Permalink
Add cursor regression test. (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jun 8, 2023
1 parent d8e7276 commit 4f2f9c1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Fantomas.Core.Tests/CursorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,30 @@ let ``cursor inside a node between defines`` () =
"""
(3, 4)
|> assertCursor (2, 0)

[<Test>]
let ``cursor after try keyword`` () =
formatWithCursor
"""
namespace JetBrains.ReSharper.Plugins.FSharp.Services.Formatter
[<CodeCleanupModule>]
type FSharpReformatCode(textControlManager: ITextControlManager) =
member x.Process(sourceFile, rangeMarker, _, _, _) =
if isNotNull rangeMarker then
try
let range = ofDocumentRange rangeMarker.DocumentRange
let formatted = fantomasHost.FormatSelection(filePath, range, text, settings, parsingOptions, newLineText)
let offset = rangeMarker.DocumentRange.StartOffset.Offset
let oldLength = rangeMarker.DocumentRange.Length
let documentChange = DocumentChange(document, offset, oldLength, formatted, stamp, modificationSide)
use _ = WriteLockCookie.Create()
document.ChangeDocument(documentChange, TimeStamp.NextValue)
sourceFile.GetPsiServices().Files.CommitAllDocuments()
with _ -> ()
else
let textControl = textControlManager.VisibleTextControls |> Seq.find (fun c -> c.Document == document)
cursorPosition = textControl.Caret.Position.Value.ToDocLineColumn();
"""
(8, 19)
|> assertCursor (7, 15)

0 comments on commit 4f2f9c1

Please sign in to comment.