From c57fe98c97031b3167ca5d322b127819debeac6a Mon Sep 17 00:00:00 2001 From: kerams Date: Thu, 6 Jul 2023 11:07:30 +0200 Subject: [PATCH 1/2] Enable completions in enum case value expression --- src/Compiler/Service/ServiceParsedInputOps.fs | 12 +++++++++--- .../FSharp.Editor.Tests/CompletionProviderTests.fs | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index a0f8a810ccb..efd36a80d34 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1520,9 +1520,15 @@ module ParsedInput = None) | _ -> None) - member _.VisitEnumDefn(_, _, _) = - // No completions anywhere in an enum, except in attributes, which is established earlier in VisitAttributeApplication - Some CompletionContext.Invalid + member _.VisitEnumDefn(_, cases, _) = + cases + |> List.tryPick (fun (SynEnumCase (ident = SynIdent (ident = id))) -> + if rangeContainsPos id.idRange pos then + // No completions in an enum case identifier + Some CompletionContext.Invalid + else + // The value expression should still get completions + None) member _.VisitTypeAbbrev(_, _, range) = if rangeContainsPos range pos then diff --git a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs index eab0a63997a..85eee176393 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs @@ -1281,11 +1281,15 @@ type A = l let ``No completion on enum case identifier at declaration site`` () = let fileContents = """ +let [] lit = 1 + type A = | C = 0 + | D = l """ VerifyNoCompletionList(fileContents, "| C") + VerifyCompletionList(fileContents, "| D = l", [ "lit" ], []) [] let ``Completion list in generic function body contains type parameter`` () = From 9b7136211839391683f920c087a35361589cb59c Mon Sep 17 00:00:00 2001 From: kerams Date: Thu, 6 Jul 2023 11:13:58 +0200 Subject: [PATCH 2/2] Why, Fantomas, why? --- src/Compiler/Service/ServiceParsedInputOps.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index efd36a80d34..4b66db0d4fd 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1522,7 +1522,7 @@ module ParsedInput = member _.VisitEnumDefn(_, cases, _) = cases - |> List.tryPick (fun (SynEnumCase (ident = SynIdent (ident = id))) -> + |> List.tryPick (fun (SynEnumCase(ident = SynIdent (ident = id))) -> if rangeContainsPos id.idRange pos then // No completions in an enum case identifier Some CompletionContext.Invalid