Skip to content

Commit faf3864

Browse files
committed
add a few more empty cases
1 parent 7d5ba83 commit faf3864

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

analysis/src/CompletionBackEndRevamped.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ let completeEmptyPattern ~env ~package typ =
2929
Completion.create ?typeArgContext "{}" ~includesSnippets:true
3030
~insertText:"{$0}" ~sortText:"A" ~kind:(Value typ) ~env;
3131
]
32+
| Tarray _ ->
33+
[
34+
Completion.create ?typeArgContext "[]" ~includesSnippets:true
35+
~insertText:"[$0]" ~sortText:"A" ~kind:(Value typ) ~env;
36+
]
37+
| Tbool _ ->
38+
[
39+
Completion.create ?typeArgContext "true" ~includesSnippets:true
40+
~insertText:"true" ~sortText:"A" ~kind:(Value typ) ~env;
41+
Completion.create ?typeArgContext "false" ~includesSnippets:true
42+
~insertText:"false" ~sortText:"A" ~kind:(Value typ) ~env;
43+
]
3244
| _ -> [])
3345

3446
let processCompletable ~debug ~full ~scope ~env ~pos

analysis/src/TypeUtils.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,19 +346,19 @@ let rec extractType ?(printOpeningDebug = true)
346346
match t.desc with
347347
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) ->
348348
extractType ?typeArgContext ~printOpeningDebug:false ~env ~package t1
349-
| Tconstr (Path.Pident {name = "option"}, [payloadTypeExpr], _) ->
349+
| Tconstr (p, [payloadTypeExpr], _) when Path.same p Predef.path_option ->
350350
Some (Toption (env, TypeExpr payloadTypeExpr), typeArgContext)
351-
| Tconstr (Path.Pident {name = "promise"}, [payloadTypeExpr], _) ->
351+
| Tconstr (p, [payloadTypeExpr], _) when Path.same p Predef.path_promise ->
352352
Some (Tpromise (env, payloadTypeExpr), typeArgContext)
353-
| Tconstr (Path.Pident {name = "array"}, [payloadTypeExpr], _) ->
353+
| Tconstr (p, [payloadTypeExpr], _) when Path.same p Predef.path_array ->
354354
Some (Tarray (env, TypeExpr payloadTypeExpr), typeArgContext)
355-
| Tconstr (Path.Pident {name = "result"}, [okType; errorType], _) ->
355+
| Tconstr (p, [okType; errorType], _) when Path.same p Predef.path_result ->
356356
Some (Tresult {env; okType; errorType}, typeArgContext)
357-
| Tconstr (Path.Pident {name = "bool"}, [], _) ->
357+
| Tconstr (p, [], _) when Path.same p Predef.path_bool ->
358358
Some (Tbool env, typeArgContext)
359-
| Tconstr (Path.Pident {name = "string"}, [], _) ->
359+
| Tconstr (p, [], _) when Path.same p Predef.path_string ->
360360
Some (Tstring env, typeArgContext)
361-
| Tconstr (Path.Pident {name = "exn"}, [], _) ->
361+
| Tconstr (p, [], _) when Path.same p Predef.path_exn ->
362362
Some (Texn env, typeArgContext)
363363
| Tarrow _ -> (
364364
match extractFunctionType2 ?typeArgContext t ~env ~package with

tests/analysis_new_tests/tests/test.js.snapshot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ exports[`RecordFieldCompletions.res - Record field completion in nested record 1
55
exports[`RecordFieldCompletions.res - Record field completion in nested record, another level 1`] = `
66
"Complete /Users/zth/OSS/rescript-compiler/tests/analysis_new_tests/tests/test_files/.build/RecordFieldCompletions_2.res 1:45\\nposCursor:[1:45] posNoWhite:[1:44] Found expr:[1:8->1:45]\\nPackage opens Stdlib.place holder Pervasives.JsxModules.place holder\\nResolved opens 1 Stdlib\\n[{\\n \\"label\\": \\"name\\",\\n \\"kind\\": 5,\\n \\"tags\\": [],\\n \\"detail\\": \\"string\\",\\n \\"documentation\\": {\\"kind\\": \\"markdown\\", \\"value\\": \\"\`\`\`rescript\\\\nname: string\\\\n\`\`\`\\\\n\\\\n\`\`\`rescript\\\\ntype \\\\\\\\\\\\\\"nestedTestRecord.nested\\\\\\" = {\\\\n name: string,\\\\n oneMoreLevel: {here: bool},\\\\n}\\\\n\`\`\`\\"}\\n }, {\\n \\"label\\": \\"oneMoreLevel\\",\\n \\"kind\\": 5,\\n \\"tags\\": [],\\n \\"detail\\": \\"\\\\\\\\\\\\\\"nestedTestRecord.nested.oneMoreLevel\\\\\\"\\",\\n \\"documentation\\": {\\"kind\\": \\"markdown\\", \\"value\\": \\"\`\`\`rescript\\\\noneMoreLevel: \\\\\\\\\\\\\\"nestedTestRecord.nested.oneMoreLevel\\\\\\"\\\\n\`\`\`\\\\n\\\\n\`\`\`rescript\\\\ntype \\\\\\\\\\\\\\"nestedTestRecord.nested\\\\\\" = {\\\\n name: string,\\\\n oneMoreLevel: {here: bool},\\\\n}\\\\n\`\`\`\\"}\\n }]\\n\\n"
77
`;
8+
9+
exports[`SwitchCaseCompletions.res - Empty case, array 1`] = `
10+
"Complete /Users/zth/OSS/rescript-compiler/tests/analysis_new_tests/tests/test_files/.build/SwitchCaseCompletions_1.res 4:4\\nposCursor:[4:4] posNoWhite:[4:2] Found expr:[3:8->6:1]\\nPackage opens Stdlib.place holder Pervasives.JsxModules.place holder\\nResolved opens 1 Stdlib\\n[{\\n \\"label\\": \\"[]\\",\\n \\"kind\\": 12,\\n \\"tags\\": [],\\n \\"detail\\": \\"array<string>\\",\\n \\"documentation\\": null,\\n \\"sortText\\": \\"A\\",\\n \\"insertText\\": \\"[$0]\\",\\n \\"insertTextFormat\\": 2\\n }]\\n\\n"
11+
`;
12+
13+
exports[`SwitchCaseCompletions.res - Empty case, bool 1`] = `
14+
"Complete /Users/zth/OSS/rescript-compiler/tests/analysis_new_tests/tests/test_files/.build/SwitchCaseCompletions_3.res 2:4\\nposCursor:[2:4] posNoWhite:[2:2] Found expr:[1:8->4:1]\\nPackage opens Stdlib.place holder Pervasives.JsxModules.place holder\\nResolved opens 1 Stdlib\\n[{\\n \\"label\\": \\"true\\",\\n \\"kind\\": 12,\\n \\"tags\\": [],\\n \\"detail\\": \\"bool\\",\\n \\"documentation\\": null,\\n \\"sortText\\": \\"A\\",\\n \\"insertText\\": \\"true\\",\\n \\"insertTextFormat\\": 2\\n }, {\\n \\"label\\": \\"false\\",\\n \\"kind\\": 12,\\n \\"tags\\": [],\\n \\"detail\\": \\"bool\\",\\n \\"documentation\\": null,\\n \\"sortText\\": \\"A\\",\\n \\"insertText\\": \\"false\\",\\n \\"insertTextFormat\\": 2\\n }]\\n\\n"
15+
`;
16+
17+
exports[`SwitchCaseCompletions.res - Empty case, record 1`] = `
18+
"Complete /Users/zth/OSS/rescript-compiler/tests/analysis_new_tests/tests/test_files/.build/SwitchCaseCompletions_2.res 2:4\\nposCursor:[2:4] posNoWhite:[2:2] Found expr:[1:8->4:1]\\nPackage opens Stdlib.place holder Pervasives.JsxModules.place holder\\nResolved opens 1 Stdlib\\n[{\\n \\"label\\": \\"{}\\",\\n \\"kind\\": 12,\\n \\"tags\\": [],\\n \\"detail\\": \\"TestTypeDefs.nestedTestRecord\\",\\n \\"documentation\\": {\\"kind\\": \\"markdown\\", \\"value\\": \\"\`\`\`rescript\\\\ntype nestedTestRecord = {\\\\n test: bool,\\\\n nested: {name: string, oneMoreLevel: {here: bool}},\\\\n}\\\\n\`\`\`\\"},\\n \\"sortText\\": \\"A\\",\\n \\"insertText\\": \\"{$0}\\",\\n \\"insertTextFormat\\": 2\\n }]\\n\\n"
19+
`;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// == TEST: Empty case, array
2+
let someStringArr = ["hello"]
3+
4+
let x = switch someStringArr {
5+
|
6+
// ^com
7+
}
8+
9+
// == TEST: Empty case, record
10+
let x = switch TestTypeDefs.nestedTestRecord {
11+
|
12+
// ^com
13+
}
14+
15+
// == TEST: Empty case, bool
16+
let x = switch true {
17+
|
18+
// ^com
19+
}

0 commit comments

Comments
 (0)