From dab2b86dde2ea88453b9b42ff48bf70373f55c89 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 18 Mar 2024 16:46:26 +0100 Subject: [PATCH 1/3] Completion: fix for unfinished record field decl --- src/Compiler/Service/ServiceParsedInputOps.fs | 10 ++++++---- tests/service/CompletionTests.fs | 9 ++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index 90062e81c68..c93fb398984 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1646,12 +1646,14 @@ module ParsedInput = member _.VisitRecordDefn(_, fields, range) = fields - |> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange)) -> - match idOpt with - | Some id when rangeContainsPos id.idRange pos -> + |> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange; fieldType = fieldType)) -> + match idOpt, fieldType with + | Some id, _ when rangeContainsPos id.idRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration true)) | _ when rangeContainsPos fieldRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration false)) - | _ -> None) + | _, SynType.FromParseError _ -> 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.orElseWith (fun _ -> if rangeContainsPos range pos then diff --git a/tests/service/CompletionTests.fs b/tests/service/CompletionTests.fs index f973c434377..c3859e0b82f 100644 --- a/tests/service/CompletionTests.fs +++ b/tests/service/CompletionTests.fs @@ -80,4 +80,11 @@ let ``Underscore dot lambda - method completion`` () = let myFancyFunc (x:string) = x |> _.ToL""" - assertHasItemWithNames ["ToLower"] info \ No newline at end of file + assertHasItemWithNames ["ToLower"] info + +[] +let ``Type decl - Record - Field type 01`` () = + let info = getCompletionInfo "type Record = { Field: }" (2, 23) """ +type Record = { Field: } +""" + assertHasItemWithNames ["string"] info From 9457701976c2bcfd57150d53986644b6639ade30 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 18 Mar 2024 17:05:43 +0100 Subject: [PATCH 2/3] Fantomas --- src/Compiler/Service/ServiceParsedInputOps.fs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index c93fb398984..d739526a025 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1652,8 +1652,7 @@ module ParsedInput = Some(CompletionContext.RecordField(RecordContext.Declaration true)) | _ when rangeContainsPos fieldRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration false)) | _, SynType.FromParseError _ -> Some(CompletionContext.RecordField(RecordContext.Declaration false)) - | _ -> None - ) + | _ -> None) // No completions in a record outside of all fields, except in attributes, which is established earlier in VisitAttributeApplication |> Option.orElseWith (fun _ -> if rangeContainsPos range pos then From 3f0c044fe060438da279848749766e323b566776 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 18 Mar 2024 17:16:03 +0100 Subject: [PATCH 3/3] Release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.300.md | 1 + 1 file changed, 1 insertion(+) 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 e68afa41dc8..19bfe2eb336 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -21,6 +21,7 @@ * Parser: fix pattern range for idents with trivia ([PR #16824](https://github.com/dotnet/fsharp/pull/16824)) * Fix broken code completion after a record type declaration ([PR #16813](https://github.com/dotnet/fsharp/pull/16813)) * Enforce AttributeTargets on enums ([PR #16887](https://github.com/dotnet/fsharp/pull/16887)) +* Completion: fix for unfinished record field decl ([PR #16893](https://github.com/dotnet/fsharp/pull/16893)) ### Added