Skip to content

Commit e3c64a4

Browse files
authored
Enable completions in enum case value expression (#15568)
1 parent e98c553 commit e3c64a4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Compiler/Service/ServiceParsedInputOps.fs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,9 +1520,15 @@ module ParsedInput =
15201520
None)
15211521
| _ -> None)
15221522

1523-
member _.VisitEnumDefn(_, _, _) =
1524-
// No completions anywhere in an enum, except in attributes, which is established earlier in VisitAttributeApplication
1525-
Some CompletionContext.Invalid
1523+
member _.VisitEnumDefn(_, cases, _) =
1524+
cases
1525+
|> List.tryPick (fun (SynEnumCase(ident = SynIdent (ident = id))) ->
1526+
if rangeContainsPos id.idRange pos then
1527+
// No completions in an enum case identifier
1528+
Some CompletionContext.Invalid
1529+
else
1530+
// The value expression should still get completions
1531+
None)
15261532

15271533
member _.VisitTypeAbbrev(_, _, range) =
15281534
if rangeContainsPos range pos then

vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,11 +1290,15 @@ type A = l
12901290
let ``No completion on enum case identifier at declaration site`` () =
12911291
let fileContents =
12921292
"""
1293+
let [<Literal>] lit = 1
1294+
12931295
type A =
12941296
| C = 0
1297+
| D = l
12951298
"""
12961299

12971300
VerifyNoCompletionList(fileContents, "| C")
1301+
VerifyCompletionList(fileContents, "| D = l", [ "lit" ], [])
12981302

12991303
[<Fact>]
13001304
let ``Completion list in generic function body contains type parameter`` () =

0 commit comments

Comments
 (0)