From 51cc49dd222a6b924e9a6c6f97e1f53ed283dc11 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 4 Jan 2025 22:58:18 +0100 Subject: [PATCH 1/2] fix issue where type arg ctx wasnt passed along --- analysis/src/TypeUtils.ml | 7 ++++--- analysis/tests/src/Support.res | 4 ++++ analysis/tests/src/TypeArgCtx.res | 9 +++++++++ .../tests/src/expected/Completion.res.txt | 10 ++++++++++ .../src/expected/CompletionJsxProps.res.txt | 10 ++++++++++ analysis/tests/src/expected/Support.res.txt | 0 .../tests/src/expected/TypeArgCtx.res.txt | 20 +++++++++++++++++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 analysis/tests/src/Support.res create mode 100644 analysis/tests/src/TypeArgCtx.res create mode 100644 analysis/tests/src/expected/Support.res.txt create mode 100644 analysis/tests/src/expected/TypeArgCtx.res.txt diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index 2394f2803..e21433aac 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -660,7 +660,7 @@ let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx Toption (env, ExtractedType typ) ) -> if Debug.verbose () then print_endline "[nested]--> moving into option Some"; - typ |> resolveNested ~env ~full ~nested + typ |> resolveNested ?typeArgContext ~env ~full ~nested | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, Toption (env, TypeExpr typ) ) -> if Debug.verbose () then @@ -720,7 +720,8 @@ let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx | Some {args = InlineRecord fields} when itemNum = 0 -> if Debug.verbose () then print_endline "[nested]--> found constructor (inline record)"; - TinlineRecord {env; fields} |> resolveNested ~env ~full ~nested + TinlineRecord {env; fields} + |> resolveNested ?typeArgContext ~env ~full ~nested | _ -> None) | ( NPolyvariantPayload {constructorName; itemNum}, Tpolyvariant {env; constructors} ) -> ( @@ -739,7 +740,7 @@ let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx |> Utils.Option.flatMap (fun (typ, typeArgContext) -> typ |> resolveNested ?typeArgContext ~env ~full ~nested))) | NArray, Tarray (env, ExtractedType typ) -> - typ |> resolveNested ~env ~full ~nested + typ |> resolveNested ?typeArgContext ~env ~full ~nested | NArray, Tarray (env, TypeExpr typ) -> typ |> extractType ~env ~package:full.package diff --git a/analysis/tests/src/Support.res b/analysis/tests/src/Support.res new file mode 100644 index 000000000..a0ce4ef41 --- /dev/null +++ b/analysis/tests/src/Support.res @@ -0,0 +1,4 @@ +module CatchResult = { + @tag("ok") + type t<'value> = | @as(true) Ok({value: 'value}) | @as(false) Error({errors: array}) +} diff --git a/analysis/tests/src/TypeArgCtx.res b/analysis/tests/src/TypeArgCtx.res new file mode 100644 index 000000000..fc4c0270d --- /dev/null +++ b/analysis/tests/src/TypeArgCtx.res @@ -0,0 +1,9 @@ +type someTyp = {test: bool} +let catchResult = Support.CatchResult.Ok({ + value: { + test: true, + }, +}) + +// switch catchResult { | Ok({value: }) => () +// ^com diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 6b8c8577a..13353fcf2 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1849,6 +1849,16 @@ Path T "modulePath": "TableclothMap", "filePath": "src/Completion.res" } + }, { + "label": "TypeArgCtx", + "kind": 9, + "tags": [], + "detail": "module TypeArgCtx", + "documentation": null, + "data": { + "modulePath": "TypeArgCtx", + "filePath": "src/Completion.res" + } }, { "label": "TypeAtPosCompletion", "kind": 9, diff --git a/analysis/tests/src/expected/CompletionJsxProps.res.txt b/analysis/tests/src/expected/CompletionJsxProps.res.txt index 7175c70e4..7f3115f5d 100644 --- a/analysis/tests/src/expected/CompletionJsxProps.res.txt +++ b/analysis/tests/src/expected/CompletionJsxProps.res.txt @@ -72,6 +72,16 @@ Path CompletionSupport.TestComponent.make "modulePath": "TableclothMap", "filePath": "src/CompletionJsxProps.res" } + }, { + "label": "TypeArgCtx", + "kind": 9, + "tags": [], + "detail": "module TypeArgCtx", + "documentation": null, + "data": { + "modulePath": "TypeArgCtx", + "filePath": "src/CompletionJsxProps.res" + } }, { "label": "TypeAtPosCompletion", "kind": 9, diff --git a/analysis/tests/src/expected/Support.res.txt b/analysis/tests/src/expected/Support.res.txt new file mode 100644 index 000000000..e69de29bb diff --git a/analysis/tests/src/expected/TypeArgCtx.res.txt b/analysis/tests/src/expected/TypeArgCtx.res.txt new file mode 100644 index 000000000..efd3cbc3c --- /dev/null +++ b/analysis/tests/src/expected/TypeArgCtx.res.txt @@ -0,0 +1,20 @@ +Complete src/TypeArgCtx.res 7:36 +posCursor:[7:36] posNoWhite:[7:35] Found pattern:[7:26->7:39] +Ppat_construct Ok:[7:26->7:28] +posCursor:[7:36] posNoWhite:[7:35] Found pattern:[7:29->7:38] +Completable: Cpattern Value[catchResult]->variantPayload::Ok($0), recordField(value) +Package opens Pervasives.JsxModules.place holder +Resolved opens 1 pervasives +ContextPath Value[catchResult] +Path catchResult +[{ + "label": "{}", + "kind": 22, + "tags": [], + "detail": "someTyp", + "documentation": {"kind": "markdown", "value": "```rescript\ntype someTyp = {test: bool}\n```"}, + "sortText": "A", + "insertText": "{$0}", + "insertTextFormat": 2 + }] + From 667f6312e412b9e2a391c8d542a41f637b4328fb Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 4 Jan 2025 22:59:21 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4301e619..6285dbc69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ - Add support for "dot completion everywhere". In addition to record fields, dots will now complete for object fields, and pipe completions applicable to the type the dot is on. You can also configure where the editor draws extra pipe completions from via the `@editor.completeFrom` attribute. https://github.com/rescript-lang/rescript-vscode/pull/1054 +#### :bug: Bug fix + +- Fix bug where type args stopped working in some completions when passed through inline records. https://github.com/rescript-lang/rescript-vscode/pull/1064 + ## 1.60.0 #### :rocket: New Feature