Skip to content

Commit 6506c16

Browse files
committed
hide Stdlib. and Stdlib_ in errors and editor type expr printing
1 parent 2716c0c commit 6506c16

File tree

8 files changed

+70
-27
lines changed

8 files changed

+70
-27
lines changed

compiler/ml/printtyp.ml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,48 @@ let reset_and_mark_loops_list tyl =
571571

572572
(* Disabled in classic mode when printing an unification error *)
573573

574+
let remove_stdlib t =
575+
match t.Types.desc with
576+
| Tconstr
577+
( Pdot
578+
( Pdot (Pident {name = "Stdlib"; flags}, module_name, s1),
579+
identifier,
580+
s2 ),
581+
type_params,
582+
m ) ->
583+
{
584+
t with
585+
desc =
586+
Tconstr
587+
( Pdot (Pident {name = module_name; stamp = s1; flags}, identifier, s2),
588+
type_params,
589+
m );
590+
}
591+
| Tconstr
592+
( Pdot (Pident ({name = ident_name} as ident), identifier, s1),
593+
type_params,
594+
m )
595+
when String.starts_with ~prefix:"Stdlib_" ident_name ->
596+
{
597+
t with
598+
desc =
599+
Tconstr
600+
( Pdot
601+
( Pident
602+
{
603+
ident with
604+
name = String.sub ident_name 7 (String.length ident_name - 7);
605+
},
606+
identifier,
607+
s1 ),
608+
type_params,
609+
m );
610+
}
611+
| _ -> t
612+
574613
let rec tree_of_typexp sch ty =
575614
let ty = repr ty in
615+
let ty = remove_stdlib ty in
576616
let px = proxy ty in
577617
if List.mem_assq px !names && not (List.memq px !delayed) then
578618
let mark = is_non_gen sch ty in
@@ -1406,6 +1446,8 @@ let report_unification_error ppf env ?(unif = true) tr txt1 txt2 =
14061446
wrap_printing_env env (fun () -> unification_error env unif tr txt1 ppf txt2)
14071447

14081448
let super_type_expansion ~tag t ppf t' =
1449+
let t = remove_stdlib t in
1450+
let t' = remove_stdlib t' in
14091451
let tag = Format.String_tag tag in
14101452
if same_path t t' then (
14111453
Format.pp_open_stag ppf tag;

compiler/ml/printtyp.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ val type_expansion : type_expr -> Format.formatter -> type_expr -> unit
6868
val prepare_expansion : type_expr * type_expr -> type_expr * type_expr
6969
val trace :
7070
bool -> bool -> string -> formatter -> (type_expr * type_expr) list -> unit
71+
val remove_stdlib : type_expr -> type_expr
7172
val report_unification_error :
7273
formatter ->
7374
Env.t ->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Hover src/Auto.res 2:13
2-
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```"}}
2+
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, List.t<'a>) => List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Stdlib.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Stdlib_List.resi%22%2C34%2C0%5D)\n"}}
33

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ Path MyList.m
1010
"label": "mapReverse",
1111
"kind": 12,
1212
"tags": [],
13-
"detail": "(list<'a>, 'a => 'b) => list<'b>",
13+
"detail": "(t<'a>, 'a => 'b) => t<'b>",
1414
"documentation": {"kind": "markdown", "value": "\n`mapReverse(list, f)` is equivalent to `map` function.\n\n## Examples\n\n```rescript\nlet f = x => x * x\nlet l = list{3, 4, 5}\n\nlet withMap = List.map(l, f)->List.reverse\nlet withMapReverse = l->List.mapReverse(f)\n\nConsole.log(withMap == withMapReverse) // true\n```\n"}
1515
}, {
1616
"label": "mapReverse2",
1717
"kind": 12,
1818
"tags": [],
19-
"detail": "(list<'a>, list<'b>, ('a, 'b) => 'c) => list<'c>",
19+
"detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c>",
2020
"documentation": {"kind": "markdown", "value": "\n`mapReverse2(list1, list2, f)` is equivalent to `List.zipBy(list1, list2, f)->List.reverse`.\n\n## Examples\n\n```rescript\nList.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2}\n```\n"}
2121
}, {
2222
"label": "make",
2323
"kind": 12,
2424
"tags": [],
25-
"detail": "(~length: int, 'a) => list<'a>",
25+
"detail": "(~length: int, 'a) => t<'a>",
2626
"documentation": {"kind": "markdown", "value": "\n`make(length, value)` returns a list of length `length` with each element filled\nwith `value`. Returns an empty list if `value` is negative.\n\n## Examples\n\n```rescript\nList.make(~length=3, 1) // list{1, 1, 1}\n```\n"}
2727
}, {
2828
"label": "mapWithIndex",
2929
"kind": 12,
3030
"tags": [],
31-
"detail": "(list<'a>, ('a, int) => 'b) => list<'b>",
31+
"detail": "(t<'a>, ('a, int) => 'b) => t<'b>",
3232
"documentation": {"kind": "markdown", "value": "\n`mapWithIndex(list, f)` applies `f` to each element of `list`. Function `f`\ntakes two arguments: the index starting from 0 and the element from `list`, in\nthat order.\n\n## Examples\n\n```rescript\nlist{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5}\n```\n"}
3333
}, {
3434
"label": "map",
3535
"kind": 12,
3636
"tags": [],
37-
"detail": "(list<'a>, 'a => 'b) => list<'b>",
37+
"detail": "(t<'a>, 'a => 'b) => t<'b>",
3838
"documentation": {"kind": "markdown", "value": "\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) // list{3, 4}\n```\n"}
3939
}]
4040

@@ -116,13 +116,13 @@ Path Array.
116116
"label": "getSymbol",
117117
"kind": 12,
118118
"tags": [],
119-
"detail": "(array<'a>, Stdlib_Symbol.t) => option<'b>",
119+
"detail": "(array<'a>, Symbol.t) => option<'b>",
120120
"documentation": null
121121
}, {
122122
"label": "getSymbolUnsafe",
123123
"kind": 12,
124124
"tags": [],
125-
"detail": "(array<'a>, Stdlib_Symbol.t) => 'b",
125+
"detail": "(array<'a>, Symbol.t) => 'b",
126126
"documentation": null
127127
}, {
128128
"label": "findIndexOpt",
@@ -218,7 +218,7 @@ Path Array.
218218
"label": "sort",
219219
"kind": 12,
220220
"tags": [],
221-
"detail": "(array<'a>, ('a, 'a) => Stdlib_Ordering.t) => unit",
221+
"detail": "(array<'a>, ('a, 'a) => Ordering.t) => unit",
222222
"documentation": {"kind": "markdown", "value": "\n`sort(array, comparator)` sorts `array` in-place using the `comparator` function.\n\nBeware this will *mutate* the array.\n\nSee [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) on MDN.\n\n## Examples\n\n```rescript\nlet array = [3, 2, 1]\narray->Array.sort((a, b) => float(a - b))\narray->assertEqual([1, 2, 3])\n```\n"}
223223
}, {
224224
"label": "length",
@@ -326,7 +326,7 @@ Path Array.
326326
"label": "compare",
327327
"kind": 12,
328328
"tags": [],
329-
"detail": "(\n array<'a>,\n array<'a>,\n ('a, 'a) => Stdlib_Ordering.t,\n) => Stdlib_Ordering.t",
329+
"detail": "(array<'a>, array<'a>, ('a, 'a) => Ordering.t) => Ordering.t",
330330
"documentation": null
331331
}, {
332332
"label": "join",
@@ -404,7 +404,7 @@ Path Array.
404404
"label": "setSymbol",
405405
"kind": 12,
406406
"tags": [],
407-
"detail": "(array<'a>, Stdlib_Symbol.t, 'b) => unit",
407+
"detail": "(array<'a>, Symbol.t, 'b) => unit",
408408
"documentation": null
409409
}, {
410410
"label": "equal",
@@ -458,7 +458,7 @@ Path Array.
458458
"label": "toSorted",
459459
"kind": 12,
460460
"tags": [],
461-
"detail": "(array<'a>, ('a, 'a) => Stdlib_Ordering.t) => array<'a>",
461+
"detail": "(array<'a>, ('a, 'a) => Ordering.t) => array<'a>",
462462
"documentation": {"kind": "markdown", "value": "\n`toSorted(array, comparator)` returns a new, sorted array from `array`, using the `comparator` function.\n\nSee [`Array.toSorted`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [3, 2, 1]\n\nsomeArray\n->Array.toSorted(Int.compare)\n->assertEqual([1, 2, 3])\n\nsomeArray->assertEqual([3, 2, 1]) // Original unchanged\n```\n"}
463463
}, {
464464
"label": "reduceWithIndex",
@@ -518,7 +518,7 @@ Path Array.
518518
"label": "fromIterator",
519519
"kind": 12,
520520
"tags": [],
521-
"detail": "Stdlib_Iterator.t<'a> => array<'a>",
521+
"detail": "Iterator.t<'a> => array<'a>",
522522
"documentation": {"kind": "markdown", "value": "\n`fromIterator(iterator)`\n\nCreates an array from the provided `iterator`\n\n## Examples\n\n```rescript\nMap.fromArray([(\"foo\", 1), (\"bar\", 2)])\n->Map.values\n->Array.fromIterator\n->assertEqual([1, 2])\n```\n"}
523523
}, {
524524
"label": "forEach",
@@ -1957,7 +1957,7 @@ Path this
19571957
"kind": 12,
19581958
"tags": [],
19591959
"detail": "\\\"Type Not Known\"",
1960-
"documentation": null
1960+
"documentation": {"kind": "markdown", "value": "```rescript\ntype props<'first, 'zoo, 'second> = {\n first?: 'first,\n zoo?: 'zoo,\n second: 'second,\n}\n```"}
19611961
}]
19621962

19631963
Hover src/Completion.res 349:14
@@ -2517,7 +2517,7 @@ Path Stdlib.Result.g
25172517
"kind": 12,
25182518
"tags": [],
25192519
"detail": "result<'a, 'b> => 'a",
2520-
"documentation": {"kind": "markdown", "value": "\n `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n\n switch Result.getExn(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"}
2520+
"documentation": {"kind": "markdown", "value": "\n Result types are really useful to describe the result of a certain operation\n without relying on exceptions or `option` types.\n\n This module gives you useful utilities to create and combine `Result` data.\n"}
25212521
}, {
25222522
"label": "Result.getOr",
25232523
"kind": 12,

tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Path Stdlib.Int.
260260
"label": "Int.compare",
261261
"kind": 12,
262262
"tags": [],
263-
"detail": "(int, int) => Stdlib_Ordering.t",
263+
"detail": "(int, int) => Ordering.t",
264264
"documentation": null
265265
}, {
266266
"label": "Int.toPrecision",
@@ -387,7 +387,7 @@ Path Stdlib.Int.
387387
"label": "Int.compare",
388388
"kind": 12,
389389
"tags": [],
390-
"detail": "(int, int) => Stdlib_Ordering.t",
390+
"detail": "(int, int) => Ordering.t",
391391
"documentation": null
392392
}, {
393393
"label": "Int.toPrecision",
@@ -751,7 +751,7 @@ Path Stdlib.String.s
751751
"label": "->String.searchOpt",
752752
"kind": 12,
753753
"tags": [],
754-
"detail": "(string, Stdlib_RegExp.t) => option<int>",
754+
"detail": "(string, RegExp.t) => option<int>",
755755
"documentation": {"kind": "markdown", "value": "\n`searchOpt(str, regexp)`. Like `search`, but return an `option<int>`.\n\n## Examples\n\n```rescript\nString.searchOpt(\"testing 1 2 3\", %re(\"/\\d+/\")) == Some(8)\nString.searchOpt(\"no numbers\", %re(\"/\\d+/\")) == None\n```\n"},
756756
"sortText": "searchOpt",
757757
"insertText": "->String.searchOpt",
@@ -763,7 +763,7 @@ Path Stdlib.String.s
763763
"label": "->String.splitByRegExpAtMost",
764764
"kind": 12,
765765
"tags": [],
766-
"detail": "(\n string,\n Stdlib_RegExp.t,\n ~limit: int,\n) => array<option<string>>",
766+
"detail": "(string, RegExp.t, ~limit: int) => array<option<string>>",
767767
"documentation": {"kind": "markdown", "value": "\n`splitByRegExpAtMost(str, regexp, ~limit)` splits the given `str` at every\noccurrence of `regexp` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings, the\narray will contain all the substrings.\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) on MDN.\n\n## Examples\n\n```rescript\nString.splitByRegExpAtMost(\"Hello World. How are you doing?\", %re(\"/ /\"), ~limit=3) == [\n Some(\"Hello\"),\n Some(\"World.\"),\n Some(\"How\"),\n]\n```\n"},
768768
"sortText": "splitByRegExpAtMost",
769769
"insertText": "->String.splitByRegExpAtMost",
@@ -799,7 +799,7 @@ Path Stdlib.String.s
799799
"label": "->String.setSymbol",
800800
"kind": 12,
801801
"tags": [],
802-
"detail": "(string, Stdlib_Symbol.t, 'a) => unit",
802+
"detail": "(string, Symbol.t, 'a) => unit",
803803
"documentation": null,
804804
"sortText": "setSymbol",
805805
"insertText": "->String.setSymbol",
@@ -811,7 +811,7 @@ Path Stdlib.String.s
811811
"label": "->String.splitByRegExp",
812812
"kind": 12,
813813
"tags": [],
814-
"detail": "(string, Stdlib_RegExp.t) => array<option<string>>",
814+
"detail": "(string, RegExp.t) => array<option<string>>",
815815
"documentation": {"kind": "markdown", "value": "\n`splitByRegExp(str, regexp)` splits the given `str` at every occurrence of\n`regexp` and returns an array of the resulting substrings.\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) on MDN.\n\n## Examples\n\n```rescript\nString.splitByRegExp(\"Jan,Feb,Mar\", %re(\"/,/\")) == [Some(\"Jan\"), Some(\"Feb\"), Some(\"Mar\")]\n```\n"},
816816
"sortText": "splitByRegExp",
817817
"insertText": "->String.splitByRegExp",
@@ -859,7 +859,7 @@ Path Stdlib.String.s
859859
"label": "->String.search",
860860
"kind": 12,
861861
"tags": [],
862-
"detail": "(string, Stdlib_RegExp.t) => int",
862+
"detail": "(string, RegExp.t) => int",
863863
"documentation": {"kind": "markdown", "value": "\n`search(str, regexp)` returns the starting position of the first match of\n`regexp` in the given `str`, or -1 if there is no match.\nSee [`String.search`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) on MDN.\n\n## Examples\n\n```rescript\nString.search(\"testing 1 2 3\", %re(\"/\\d+/\")) == 8\nString.search(\"no numbers\", %re(\"/\\d+/\")) == -1\n```\n"},
864864
"sortText": "search",
865865
"insertText": "->String.search",

tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Path date
99
"label": "None",
1010
"kind": 12,
1111
"tags": [],
12-
"detail": "Stdlib.Date.t",
12+
"detail": "Date.t",
1313
"documentation": {"kind": "markdown", "value": "\nA type representing a JavaScript date.\n"}
1414
}, {
1515
"label": "Some(_)",
1616
"kind": 12,
1717
"tags": [],
18-
"detail": "Stdlib.Date.t",
18+
"detail": "Date.t",
1919
"documentation": {"kind": "markdown", "value": "\nA type representing a JavaScript date.\n"},
2020
"insertText": "Some(${1:_})",
2121
"insertTextFormat": 2

tests/analysis_tests/tests/src/expected/Definition.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Definition src/Definition.res 10:23
55
{"uri": "Definition.res", "range": {"start": {"line": 6, "character": 7}, "end": {"line": 6, "character": 13}}}
66

77
Hover src/Definition.res 14:14
8-
{"contents": {"kind": "markdown", "value": "```rescript\n(list<'a>, 'a => 'b) => list<'b>\n```\n---\n\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) // list{3, 4}\n```\n"}}
8+
{"contents": {"kind": "markdown", "value": "```rescript\n(List.t<'a>, 'a => 'b) => List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Stdlib.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Stdlib_List.resi%22%2C34%2C0%5D)\n\n---\n\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) // list{3, 4}\n```\n"}}
99

1010
Hover src/Definition.res 18:14
11-
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```"}}
11+
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, List.t<'a>) => List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Stdlib.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Stdlib_List.resi%22%2C34%2C0%5D)\n"}}
1212

1313
Hover src/Definition.res 23:3
1414
{"contents": {"kind": "markdown", "value": "```rescript\n(int, int) => int\n```"}}

tests/analysis_tests/tests/src/expected/Firebase.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Path Firebase.Firestore.
2929
"label": "->Firestore.getDoc",
3030
"kind": 12,
3131
"tags": [],
32-
"detail": "documentReference<\n 'documentdata,\n> => Stdlib.Promise.t<documentSnapshot<'documentdata>>",
32+
"detail": "documentReference<\n 'documentdata,\n> => Promise.t<documentSnapshot<'documentdata>>",
3333
"documentation": null,
3434
"sortText": "getDoc",
3535
"insertText": "->Firestore.getDoc",

0 commit comments

Comments
 (0)