From abd25394621beba940b87cb0cb302d0db6077ef9 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 12 Apr 2024 16:00:19 +0200 Subject: [PATCH 1/2] make jsx completion work for React.component --- analysis/src/CompletionJsx.ml | 11 ++++++++ analysis/tests/src/CompletableComponent.res | 10 +++++++ analysis/tests/src/CompletionJsxProps.res | 10 +++++++ .../src/expected/CompletableComponent.res.txt | 0 .../src/expected/CompletionJsxProps.res.txt | 26 +++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 analysis/tests/src/CompletableComponent.res create mode 100644 analysis/tests/src/expected/CompletableComponent.res.txt diff --git a/analysis/src/CompletionJsx.ml b/analysis/src/CompletionJsx.ml index b8a279a2e..f4270add3 100644 --- a/analysis/src/CompletionJsx.ml +++ b/analysis/src/CompletionJsx.ml @@ -747,6 +747,17 @@ let getJsxLabels ~componentPath ~findTypeOfValue ~package = _ ) -> (* JSX V3 *) getFieldsV3 tObj + | Tconstr (p, [propsType], _) when Path.name p = "React.component" -> ( + let rec getPropsType (t : Types.type_expr) = + match t.desc with + | Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> getPropsType t1 + | Tconstr (path, typeArgs, _) when Path.last path = "props" -> + Some (path, typeArgs) + | _ -> None + in + match propsType |> getPropsType with + | Some (path, typeArgs) -> getFieldsV4 ~path ~typeArgs + | None -> []) | Tarrow (Nolabel, {desc = Tconstr (path, typeArgs, _)}, _, _) when Path.last path = "props" -> (* JSX V4 *) diff --git a/analysis/tests/src/CompletableComponent.res b/analysis/tests/src/CompletableComponent.res new file mode 100644 index 000000000..1ab374908 --- /dev/null +++ b/analysis/tests/src/CompletableComponent.res @@ -0,0 +1,10 @@ +type status = On | Off + +@@jsxConfig({version: 4, mode: "automatic"}) + +@react.component +let make = (~status: status, ~name: string) => { + ignore(status) + ignore(name) + React.null +} diff --git a/analysis/tests/src/CompletionJsxProps.res b/analysis/tests/src/CompletionJsxProps.res index 4d053df6b..7562778b3 100644 --- a/analysis/tests/src/CompletionJsxProps.res +++ b/analysis/tests/src/CompletionJsxProps.res @@ -34,3 +34,13 @@ let tsomeVar = #two // let _ = Js.import(CompletableComponent.make) + let make = React.lazy_(loadComponent) +} + +// let _ = 44:44] +JSX 44:36] status[44:37->44:43]=...__ghost__[0:-1->0:-1]> _children:None +Completable: Cexpression CJsxPropValue [CompletableComponentLazy] status +Package opens Pervasives.JsxModules.place holder +Resolved opens 1 pervasives +ContextPath CJsxPropValue [CompletableComponentLazy] status +Path CompletableComponentLazy.make +[{ + "label": "On", + "kind": 4, + "tags": [], + "detail": "On", + "documentation": {"kind": "markdown", "value": "```rescript\nOn\n```\n\n```rescript\ntype status = On | Off\n```"}, + "insertText": "{On}", + "insertTextFormat": 2 + }, { + "label": "Off", + "kind": 4, + "tags": [], + "detail": "Off", + "documentation": {"kind": "markdown", "value": "```rescript\nOff\n```\n\n```rescript\ntype status = On | Off\n```"}, + "insertText": "{Off}", + "insertTextFormat": 2 + }] + From b3dfb8a9c21d3834ac0f299f3af77b1fee051bfc Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 12 Apr 2024 16:03:21 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2282a94f..0417098d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ #### :nail_care: Polish - Make sure doc strings are always on top in hovers. https://github.com/rescript-lang/rescript-vscode/pull/956 +- Make JSX completion work for `make` functions of type `React.component`, like what you get when using `React.lazy_`. https://github.com/rescript-lang/rescript-vscode/pull/966 #### :rocket: New Feature