Skip to content

Commit 7f4507d

Browse files
zthcristianoc
authored andcommitted
follow options
1 parent 9934131 commit 7f4507d

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

analysis/src/TypeUtils.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested =
421421
with
422422
| Some typ -> Some (TypeExpr typ, env)
423423
| None -> None)
424+
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
425+
Toption (env, typ) ) ->
426+
Some (typ, env)
424427
| _ -> None))
425428
| patternPath :: nested -> (
426429
match t with
@@ -463,6 +466,9 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested =
463466
| Some typ ->
464467
TypeExpr typ |> resolveNestedPatternPath ~env ~full ~nested
465468
| None -> None)
469+
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
470+
Toption (env, typ) ) ->
471+
typ |> resolveNestedPatternPath ~env ~full ~nested
466472
| _ -> None))
467473

468474
let getArgs ~env (t : Types.type_expr) ~full =

analysis/tests/src/CompletionInferValues.res

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ type someRecordWithNestedStuff = {
7070
someStuff: bool,
7171
}
7272

73-
type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant)}
73+
type otherNestedRecord = {
74+
someRecord: someRecord,
75+
someTuple: (someVariant, int, somePolyVariant),
76+
optRecord: option<someRecord>,
77+
}
7478

7579
// Destructure record
7680
// let x: someRecordWithNestedStuff = Obj.magic(); let {srecord} = x; srecord.
@@ -108,6 +112,10 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int,
108112
// let x: otherNestedRecord; switch x { | {someTuple:(_, _, #three(_, str))} => str->slic }
109113
// ^com
110114

115+
// Follow options
116+
// let x: otherNestedRecord; switch x { | {optRecord:Some({name})} => name->slic }
117+
// ^com
118+
111119
let fnWithRecordCallback = (cb: someRecord => unit) => {
112120
let _ = cb
113121
}

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

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ Completable: Cpath Value[x].""
220220
"documentation": null
221221
}]
222222

223-
Complete src/CompletionInferValues.res 75:78
224-
posCursor:[75:78] posNoWhite:[75:77] Found expr:[75:70->75:78]
225-
Pexp_field [75:70->75:77] _:[110:0->75:78]
223+
Complete src/CompletionInferValues.res 79:78
224+
posCursor:[79:78] posNoWhite:[79:77] Found expr:[79:70->79:78]
225+
Pexp_field [79:70->79:77] _:[118:0->79:78]
226226
Completable: Cpath Value[srecord].""
227227
[{
228228
"label": "name",
@@ -238,9 +238,9 @@ Completable: Cpath Value[srecord].""
238238
"documentation": null
239239
}]
240240

241-
Complete src/CompletionInferValues.res 79:86
242-
posCursor:[79:86] posNoWhite:[79:85] Found expr:[79:78->79:86]
243-
Pexp_field [79:78->79:85] _:[110:0->79:86]
241+
Complete src/CompletionInferValues.res 83:86
242+
posCursor:[83:86] posNoWhite:[83:85] Found expr:[83:78->83:86]
243+
Pexp_field [83:78->83:85] _:[118:0->83:86]
244244
Completable: Cpath Value[aliased].""
245245
[{
246246
"label": "someRecord",
@@ -250,9 +250,9 @@ Completable: Cpath Value[aliased].""
250250
"documentation": null
251251
}]
252252

253-
Complete src/CompletionInferValues.res 83:103
254-
posCursor:[83:103] posNoWhite:[83:102] Found expr:[83:92->83:103]
255-
Pexp_field [83:92->83:102] _:[110:0->83:103]
253+
Complete src/CompletionInferValues.res 87:103
254+
posCursor:[87:103] posNoWhite:[87:102] Found expr:[87:92->87:103]
255+
Pexp_field [87:92->87:102] _:[118:0->87:103]
256256
Completable: Cpath Value[someRecord].""
257257
[{
258258
"label": "name",
@@ -268,8 +268,8 @@ Completable: Cpath Value[someRecord].""
268268
"documentation": null
269269
}]
270270

271-
Complete src/CompletionInferValues.res 87:81
272-
posCursor:[87:81] posNoWhite:[87:80] Found expr:[87:69->87:81]
271+
Complete src/CompletionInferValues.res 91:81
272+
posCursor:[91:81] posNoWhite:[91:80] Found expr:[91:69->91:81]
273273
Completable: Cpath Value[things]->slic
274274
[{
275275
"label": "Js.String2.sliceToEnd",
@@ -285,8 +285,8 @@ Completable: Cpath Value[things]->slic
285285
"documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"}
286286
}]
287287

288-
Complete src/CompletionInferValues.res 91:82
289-
posCursor:[91:82] posNoWhite:[91:81] Found expr:[91:70->91:82]
288+
Complete src/CompletionInferValues.res 95:82
289+
posCursor:[95:82] posNoWhite:[95:81] Found expr:[95:70->95:82]
290290
Completable: Cpath Value[someInt]->toS
291291
[{
292292
"label": "Belt.Int.toString",
@@ -296,8 +296,8 @@ Completable: Cpath Value[someInt]->toS
296296
"documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"}
297297
}]
298298

299-
Complete src/CompletionInferValues.res 95:109
300-
posCursor:[95:109] posNoWhite:[95:108] Found expr:[95:97->95:109]
299+
Complete src/CompletionInferValues.res 99:109
300+
posCursor:[99:109] posNoWhite:[99:108] Found expr:[99:97->99:109]
301301
Completable: Cpath Value[someInt]->toS
302302
[{
303303
"label": "Belt.Int.toString",
@@ -307,9 +307,9 @@ Completable: Cpath Value[someInt]->toS
307307
"documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"}
308308
}]
309309

310-
Complete src/CompletionInferValues.res 99:102
311-
posCursor:[99:102] posNoWhite:[99:101] Found expr:[99:57->99:102]
312-
posCursor:[99:102] posNoWhite:[99:101] Found expr:[99:90->99:102]
310+
Complete src/CompletionInferValues.res 103:102
311+
posCursor:[103:102] posNoWhite:[103:101] Found expr:[103:57->103:102]
312+
posCursor:[103:102] posNoWhite:[103:101] Found expr:[103:90->103:102]
313313
Completable: Cpath Value[someInt]->toS
314314
[{
315315
"label": "Belt.Int.toString",
@@ -319,8 +319,8 @@ Completable: Cpath Value[someInt]->toS
319319
"documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"}
320320
}]
321321

322-
Complete src/CompletionInferValues.res 103:88
323-
posCursor:[103:88] posNoWhite:[103:87] Found expr:[103:79->103:88]
322+
Complete src/CompletionInferValues.res 107:88
323+
posCursor:[107:88] posNoWhite:[107:87] Found expr:[107:79->107:88]
324324
Completable: Cpath Value[str]->slic
325325
[{
326326
"label": "Js.String2.sliceToEnd",
@@ -336,8 +336,8 @@ Completable: Cpath Value[str]->slic
336336
"documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"}
337337
}]
338338

339-
Complete src/CompletionInferValues.res 107:89
340-
posCursor:[107:89] posNoWhite:[107:88] Found expr:[107:80->107:89]
339+
Complete src/CompletionInferValues.res 111:89
340+
posCursor:[111:89] posNoWhite:[111:88] Found expr:[111:80->111:89]
341341
Completable: Cpath Value[str]->slic
342342
[{
343343
"label": "Js.String2.sliceToEnd",
@@ -353,12 +353,29 @@ Completable: Cpath Value[str]->slic
353353
"documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"}
354354
}]
355355

356-
Complete src/CompletionInferValues.res 115:26
357-
posCursor:[115:26] posNoWhite:[115:25] Found expr:[115:3->115:37]
358-
Pexp_apply ...[115:3->115:23] (...[115:24->115:36])
359-
posCursor:[115:26] posNoWhite:[115:25] Found expr:[115:24->115:36]
360-
posCursor:[115:26] posNoWhite:[115:25] Found pattern:[115:25->115:27]
361-
posCursor:[115:26] posNoWhite:[115:25] Found pattern:[115:25->115:27]
356+
Complete src/CompletionInferValues.res 115:80
357+
posCursor:[115:80] posNoWhite:[115:79] Found expr:[115:70->115:80]
358+
Completable: Cpath Value[name]->slic
359+
[{
360+
"label": "Js.String2.sliceToEnd",
361+
"kind": 12,
362+
"tags": [],
363+
"detail": "(t, ~from: int) => t",
364+
"documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, from:n)` returns the substring of `str` starting at character\n`n` to the end of the string.\n- If `n` is negative, then it is evaluated as `length(str - n)`.\n- If `n` is greater than the length of `str`, then sliceToEnd returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.sliceToEnd(\"abcdefg\", ~from=4) == \"efg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=-2) == \"fg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=7) == \"\"\n```\n"}
365+
}, {
366+
"label": "Js.String2.slice",
367+
"kind": 12,
368+
"tags": [],
369+
"detail": "(t, ~from: int, ~to_: int) => t",
370+
"documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"}
371+
}]
372+
373+
Complete src/CompletionInferValues.res 123:26
374+
posCursor:[123:26] posNoWhite:[123:25] Found expr:[123:3->123:37]
375+
Pexp_apply ...[123:3->123:23] (...[123:24->123:36])
376+
posCursor:[123:26] posNoWhite:[123:25] Found expr:[123:24->123:36]
377+
posCursor:[123:26] posNoWhite:[123:25] Found pattern:[123:25->123:27]
378+
posCursor:[123:26] posNoWhite:[123:25] Found pattern:[123:25->123:27]
362379
Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody
363380
[{
364381
"label": "name",

0 commit comments

Comments
 (0)