Skip to content

Commit

Permalink
Fix removeCommaEdits in ConvertPositionalDUToNamed to work for unform…
Browse files Browse the repository at this point in the history
…atted patterns (#1074)
  • Loading branch information
dawedawe committed Mar 13, 2023
1 parent 5e28e81 commit 2f20416
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/FsAutoComplete/CodeFixes/ConvertPositionalDUToNamed.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ let fix (getParseResultsForFile: GetParseResultsForFile) (getRangeText: GetRange
let notInsidePatterns =
let ranges = duFields |> List.map (fun f -> f.Range)

fun (pos: FSharp.Compiler.Text.Position) ->
ranges
|> List.forall (fun r -> not (FSharp.Compiler.Text.Range.rangeContainsPos r pos))
let rangeContainsPosLeftEdgeExclusive (r: FSharp.Compiler.Text.Range) p =
let r' = r.WithStart(r.Start.WithColumn(r.Start.Column + 1))
rangeContainsPos r' p

fun (pos: FSharp.Compiler.Text.Position) ->
ranges |> List.forall (fun r -> not (rangeContainsPosLeftEdgeExclusive r pos))

let commasBetweenFields =
toPosSeq (parenRange, sourceText)
Expand Down
12 changes: 12 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ let private convertPositionalDUToNamedTests state =
type U = U of aValue: int * boolean: int * char: char * dec: decimal * element: int
let (U(aValue = a; boolean = b; char = _; dec = _; element = _;)) = failwith "..."
"""
testCaseAsync "when the existing pattern isn't formatted well" <|
CodeFix.check server
"""
type A = A of a: int * b: bool * c: bool * d: bool
let (A($0a,b, c, d)) = A(1, true, false, false)
"""
Diagnostics.acceptAll
selectCodeFix
"""
type A = A of a: int * b: bool * c: bool * d: bool
let (A(a = a;b = b; c = c; d = d;)) = A(1, true, false, false)
"""
])

let private convertTripleSlashCommentToXmlTaggedDocTests state =
Expand Down

0 comments on commit 2f20416

Please sign in to comment.