Skip to content

Commit ef45cde

Browse files
zthcristianoc
authored andcommitted
follow arrays
1 parent 7f4507d commit ef45cde

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

analysis/src/TypeUtils.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested =
424424
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
425425
Toption (env, typ) ) ->
426426
Some (typ, env)
427+
| NArray, Tarray (env, typ) -> Some (typ, env)
427428
| _ -> None))
428429
| patternPath :: nested -> (
429430
match t with
@@ -469,6 +470,8 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested =
469470
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
470471
Toption (env, typ) ) ->
471472
typ |> resolveNestedPatternPath ~env ~full ~nested
473+
| NArray, Tarray (env, typ) ->
474+
typ |> resolveNestedPatternPath ~env ~full ~nested
472475
| _ -> None))
473476

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

analysis/tests/src/CompletionInferValues.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ type otherNestedRecord = {
116116
// let x: otherNestedRecord; switch x { | {optRecord:Some({name})} => name->slic }
117117
// ^com
118118

119+
// Follow arrays
120+
// let x: array<otherNestedRecord>; switch x { | [inner] => inner.s }
121+
// ^com
122+
119123
let fnWithRecordCallback = (cb: someRecord => unit) => {
120124
let _ = cb
121125
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Completable: Cpath Value[x].""
222222

223223
Complete src/CompletionInferValues.res 79:78
224224
posCursor:[79:78] posNoWhite:[79:77] Found expr:[79:70->79:78]
225-
Pexp_field [79:70->79:77] _:[118:0->79:78]
225+
Pexp_field [79:70->79:77] _:[122:0->79:78]
226226
Completable: Cpath Value[srecord].""
227227
[{
228228
"label": "name",
@@ -240,7 +240,7 @@ Completable: Cpath Value[srecord].""
240240

241241
Complete src/CompletionInferValues.res 83:86
242242
posCursor:[83:86] posNoWhite:[83:85] Found expr:[83:78->83:86]
243-
Pexp_field [83:78->83:85] _:[118:0->83:86]
243+
Pexp_field [83:78->83:85] _:[122:0->83:86]
244244
Completable: Cpath Value[aliased].""
245245
[{
246246
"label": "someRecord",
@@ -252,7 +252,7 @@ Completable: Cpath Value[aliased].""
252252

253253
Complete src/CompletionInferValues.res 87:103
254254
posCursor:[87:103] posNoWhite:[87:102] Found expr:[87:92->87:103]
255-
Pexp_field [87:92->87:102] _:[118:0->87:103]
255+
Pexp_field [87:92->87:102] _:[122:0->87:103]
256256
Completable: Cpath Value[someRecord].""
257257
[{
258258
"label": "name",
@@ -370,12 +370,30 @@ Completable: Cpath Value[name]->slic
370370
"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"}
371371
}]
372372

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]
373+
Complete src/CompletionInferValues.res 119:67
374+
posCursor:[119:67] posNoWhite:[119:66] Found expr:[119:60->119:67]
375+
Pexp_field [119:60->119:65] s:[119:66->119:67]
376+
Completable: Cpath Value[inner].s
377+
[{
378+
"label": "someRecord",
379+
"kind": 5,
380+
"tags": [],
381+
"detail": "someRecord: someRecord\n\ntype otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant), optRecord: option<someRecord>}",
382+
"documentation": null
383+
}, {
384+
"label": "someTuple",
385+
"kind": 5,
386+
"tags": [],
387+
"detail": "someTuple: (someVariant, int, somePolyVariant)\n\ntype otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant), optRecord: option<someRecord>}",
388+
"documentation": null
389+
}]
390+
391+
Complete src/CompletionInferValues.res 127:26
392+
posCursor:[127:26] posNoWhite:[127:25] Found expr:[127:3->127:37]
393+
Pexp_apply ...[127:3->127:23] (...[127:24->127:36])
394+
posCursor:[127:26] posNoWhite:[127:25] Found expr:[127:24->127:36]
395+
posCursor:[127:26] posNoWhite:[127:25] Found pattern:[127:25->127:27]
396+
posCursor:[127:26] posNoWhite:[127:25] Found pattern:[127:25->127:27]
379397
Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody
380398
[{
381399
"label": "name",

0 commit comments

Comments
 (0)