Skip to content

Commit 85a72dc

Browse files
authored
Fix issue where type arg ctx wasnt passed along (#1064)
* fix issue where type arg ctx wasnt passed along * changelog
1 parent 76adc98 commit 85a72dc

8 files changed

+61
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
- 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
1818

19+
#### :bug: Bug fix
20+
21+
- Fix bug where type args stopped working in some completions when passed through inline records. https://github.com/rescript-lang/rescript-vscode/pull/1064
22+
1923
## 1.60.0
2024

2125
#### :rocket: New Feature

analysis/src/TypeUtils.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx
660660
Toption (env, ExtractedType typ) ) ->
661661
if Debug.verbose () then
662662
print_endline "[nested]--> moving into option Some";
663-
typ |> resolveNested ~env ~full ~nested
663+
typ |> resolveNested ?typeArgContext ~env ~full ~nested
664664
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
665665
Toption (env, TypeExpr typ) ) ->
666666
if Debug.verbose () then
@@ -720,7 +720,8 @@ let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx
720720
| Some {args = InlineRecord fields} when itemNum = 0 ->
721721
if Debug.verbose () then
722722
print_endline "[nested]--> found constructor (inline record)";
723-
TinlineRecord {env; fields} |> resolveNested ~env ~full ~nested
723+
TinlineRecord {env; fields}
724+
|> resolveNested ?typeArgContext ~env ~full ~nested
724725
| _ -> None)
725726
| ( NPolyvariantPayload {constructorName; itemNum},
726727
Tpolyvariant {env; constructors} ) -> (
@@ -739,7 +740,7 @@ let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx
739740
|> Utils.Option.flatMap (fun (typ, typeArgContext) ->
740741
typ |> resolveNested ?typeArgContext ~env ~full ~nested)))
741742
| NArray, Tarray (env, ExtractedType typ) ->
742-
typ |> resolveNested ~env ~full ~nested
743+
typ |> resolveNested ?typeArgContext ~env ~full ~nested
743744
| NArray, Tarray (env, TypeExpr typ) ->
744745
typ
745746
|> extractType ~env ~package:full.package

analysis/tests/src/Support.res

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CatchResult = {
2+
@tag("ok")
3+
type t<'value> = | @as(true) Ok({value: 'value}) | @as(false) Error({errors: array<string>})
4+
}

analysis/tests/src/TypeArgCtx.res

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type someTyp = {test: bool}
2+
let catchResult = Support.CatchResult.Ok({
3+
value: {
4+
test: true,
5+
},
6+
})
7+
8+
// switch catchResult { | Ok({value: }) => ()
9+
// ^com

analysis/tests/src/expected/Completion.res.txt

+10
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,16 @@ Path T
18491849
"modulePath": "TableclothMap",
18501850
"filePath": "src/Completion.res"
18511851
}
1852+
}, {
1853+
"label": "TypeArgCtx",
1854+
"kind": 9,
1855+
"tags": [],
1856+
"detail": "module TypeArgCtx",
1857+
"documentation": null,
1858+
"data": {
1859+
"modulePath": "TypeArgCtx",
1860+
"filePath": "src/Completion.res"
1861+
}
18521862
}, {
18531863
"label": "TypeAtPosCompletion",
18541864
"kind": 9,

analysis/tests/src/expected/CompletionJsxProps.res.txt

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ Path CompletionSupport.TestComponent.make
7272
"modulePath": "TableclothMap",
7373
"filePath": "src/CompletionJsxProps.res"
7474
}
75+
}, {
76+
"label": "TypeArgCtx",
77+
"kind": 9,
78+
"tags": [],
79+
"detail": "module TypeArgCtx",
80+
"documentation": null,
81+
"data": {
82+
"modulePath": "TypeArgCtx",
83+
"filePath": "src/CompletionJsxProps.res"
84+
}
7585
}, {
7686
"label": "TypeAtPosCompletion",
7787
"kind": 9,

analysis/tests/src/expected/Support.res.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Complete src/TypeArgCtx.res 7:36
2+
posCursor:[7:36] posNoWhite:[7:35] Found pattern:[7:26->7:39]
3+
Ppat_construct Ok:[7:26->7:28]
4+
posCursor:[7:36] posNoWhite:[7:35] Found pattern:[7:29->7:38]
5+
Completable: Cpattern Value[catchResult]->variantPayload::Ok($0), recordField(value)
6+
Package opens Pervasives.JsxModules.place holder
7+
Resolved opens 1 pervasives
8+
ContextPath Value[catchResult]
9+
Path catchResult
10+
[{
11+
"label": "{}",
12+
"kind": 22,
13+
"tags": [],
14+
"detail": "someTyp",
15+
"documentation": {"kind": "markdown", "value": "```rescript\ntype someTyp = {test: bool}\n```"},
16+
"sortText": "A",
17+
"insertText": "{$0}",
18+
"insertTextFormat": 2
19+
}]
20+

0 commit comments

Comments
 (0)