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 removeCommaEdits in ConvertPositionalDUToNamed to work for unformatted patterns #1074

Merged
Show file tree
Hide file tree
Changes from all 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
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