未验证 提交 567ea957 编写于 作者: K kerams 提交者: GitHub

Improve record completions (#12873)

上级 8c6588a9
......@@ -1105,12 +1105,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)) ->
......
......@@ -757,6 +757,20 @@ type A<'lType> = { 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 = """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册