Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/fsharp/service/ServiceParsedInputOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,12 +1095,15 @@ module ParsedInput =
Some CompletionContext.PatternType
| _ -> defaultTraverse ty

member _.VisitRecordDefn(_path, fields, _range) =
fields |> List.tryPick (fun (SynField (idOpt = idOpt; range = fieldRange)) ->
member _.VisitRecordDefn(_path, fields, range) =
fields
|> List.tryPick (fun (SynField (idOpt = idOpt; range = fieldRange)) ->
match idOpt 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)
// No completions in a record outside of all fields
|> Option.orElseWith (fun () -> if rangeContainsPos range pos then Some CompletionContext.Invalid else None)

member _.VisitUnionDefn(_path, cases, _range) =
cases |> List.tryPick (fun (SynUnionCase (ident = id; caseType = caseType)) ->
Expand Down
14 changes: 14 additions & 0 deletions vsintegration/tests/UnitTests/CompletionProviderTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,20 @@ type A = { Field: l }
"""
VerifyCompletionList(fileContents, "Field: l", ["LanguagePrimitives"; "List"], ["let"; "log"])

[<Test>]
let ``No completion on record stub with no fields at declaration site``() =
let fileContents = """
type A = { }
"""
VerifyNoCompletionList(fileContents, "{ ")

[<Test>]
let ``No completion on record outside of all fields at declaration site``() =
let fileContents = """
type A = { Field: string; }
"""
VerifyNoCompletionList(fileContents, "; ")

[<Test>]
let ``No completion on union case identifier at declaration site``() =
let fileContents = """
Expand Down