Skip to content

Commit

Permalink
Completion: fix for unfinished record field decl (#16893)
Browse files Browse the repository at this point in the history
* Completion: fix for unfinished record field decl

* Fantomas

* Release notes
  • Loading branch information
auduchinok authored Mar 19, 2024
1 parent 5a19ccf commit b353688
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
* 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))
* Enforce AttributeTargets on delegates ([PR #16891](https://github.com/dotnet/fsharp/pull/16891))


### Added

* The stackguard depth for ILPdbWriter.unshadowScopes can be modified via the environment variable `FSHARP_ILPdb_UnshadowScopes_StackGuardDepth`([PR #16583](https://github.com/dotnet/fsharp/pull/16583))
Expand Down
7 changes: 4 additions & 3 deletions src/Compiler/Service/ServiceParsedInputOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,11 +1646,12 @@ 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))
| _, 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 _ ->
Expand Down
9 changes: 8 additions & 1 deletion tests/service/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,11 @@ let ``Underscore dot lambda - method completion`` () =
let myFancyFunc (x:string) =
x
|> _.ToL"""
assertHasItemWithNames ["ToLower"] info
assertHasItemWithNames ["ToLower"] info

[<Test>]
let ``Type decl - Record - Field type 01`` () =
let info = getCompletionInfo "type Record = { Field: }" (2, 23) """
type Record = { Field: }
"""
assertHasItemWithNames ["string"] info

0 comments on commit b353688

Please sign in to comment.