diff --git a/analysis/src/CompletionJsx.ml b/analysis/src/CompletionJsx.ml index c260a1c6e..d9cfe4557 100644 --- a/analysis/src/CompletionJsx.ml +++ b/analysis/src/CompletionJsx.ml @@ -559,6 +559,19 @@ let getJsxLabels ~componentPath ~findTypeOfValue ~package = && Path.last path = "props" -> (* JSX V4 external or interface *) getFieldsV4 ~path ~typeArgs + | Tarrow (Nolabel, typ, _, _) -> ( + (* Component without the JSX PPX, like a make fn taking a hand-written + type props. *) + let rec digToConstr typ = + match typ.Types.desc with + | Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> digToConstr t1 + | Tconstr (path, typeArgs, _) when Path.last path = "props" -> + Some (path, typeArgs) + | _ -> None + in + match digToConstr typ with + | None -> [] + | Some (path, typeArgs) -> getFieldsV4 ~path ~typeArgs) | _ -> [] in typ |> getLabels diff --git a/analysis/tests/src/CompletionJsx.res b/analysis/tests/src/CompletionJsx.res index c08889d8b..df43305ae 100644 --- a/analysis/tests/src/CompletionJsx.res +++ b/analysis/tests/src/CompletionJsx.res @@ -31,3 +31,15 @@ module SomeComponent = { } } + +module CompWithoutJsxPpx = { + type props = {name: string} + + let make = ({name}) => { + ignore(name) + React.null + } +} + +// a <> "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} }] +Complete src/CompletionJsx.res 43:23 +posCursor:[43:23] posNoWhite:[43:22] Found expr:[43:4->43:23] +JSX 43:21] n[43:22->43:23]=...[43:22->43:23]> _children:None +Completable: Cjsx([CompWithoutJsxPpx], n, [n]) +[{ + "label": "name", + "kind": 4, + "tags": [], + "detail": "string", + "documentation": null + }] +