diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index 148f3734185..730ed7564c0 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -16,6 +16,7 @@ * Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692)) * Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764)) * Disallow using base to invoke an abstract base method. ([Issue #13926](https://github.com/dotnet/fsharp/issues/13926), [PR #16773](https://github.com/dotnet/fsharp/pull/16773)) +* Fix broken code completion after a record type declaration ([PR #16813]([Title](https://github.com/dotnet/fsharp/pull/16813))) ### Added diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index f1a8d3e9737..90062e81c68 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1644,7 +1644,7 @@ module ParsedInput = | SynType.LongIdent _ when rangeContainsPos ty.Range pos -> Some CompletionContext.Type | _ -> defaultTraverse ty - member _.VisitRecordDefn(_, fields, _) = + member _.VisitRecordDefn(_, fields, range) = fields |> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange)) -> match idOpt with @@ -1653,7 +1653,11 @@ module ParsedInput = | _ when rangeContainsPos fieldRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration false)) | _ -> None) // No completions in a record outside of all fields, except in attributes, which is established earlier in VisitAttributeApplication - |> Option.orElse (Some CompletionContext.Invalid) + |> Option.orElseWith (fun _ -> + if rangeContainsPos range pos then + Some CompletionContext.Invalid + else + None) member _.VisitUnionDefn(_, cases, _) = cases diff --git a/tests/service/CompletionTests.fs b/tests/service/CompletionTests.fs index 349647e0fa3..f973c434377 100644 --- a/tests/service/CompletionTests.fs +++ b/tests/service/CompletionTests.fs @@ -17,6 +17,15 @@ let assertHasItemWithNames names (completionInfo: DeclarationListInfo) = for name in names do Assert.That(Set.contains name itemNames, $"{name} not found in {itemNames}") +[] +let ``Expr - After record decl`` () = + let info = getCompletionInfo "{ Fi }" (4, 0) """ +type Record = { Field: int } + + +""" + assertHasItemWithNames ["ignore"] info + [] let ``Expr - record - field 01 - anon module`` () = let info = getCompletionInfo "{ Fi }" (4, 3) """