Skip to content

Commit 5ea6b00

Browse files
committed
change approach to roughly the same as Pervasives use
1 parent 07ab10f commit 5ea6b00

File tree

8 files changed

+23
-65
lines changed

8 files changed

+23
-65
lines changed

analysis/src/PrintType.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ let printExpr ?(lineWidth = 60) typ =
66

77
let printDecl ?printNameAsIs ~recStatus name decl =
88
Printtyp.reset_names ();
9-
let name =
10-
if
11-
String.starts_with ~prefix:"Stdlib_" name
12-
|| String.starts_with ~prefix:"Stdlib." name
13-
then String.sub name 7 (String.length name - 7)
14-
else name
15-
in
169
Res_doc.to_string ~width:60
1710
(Res_outcome_printer.print_out_sig_item_doc ?print_name_as_is:printNameAsIs
1811
(Printtyp.tree_of_type_declaration (Ident.create name) decl recStatus))

compiler/ml/printtyp.ml

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,32 @@ let ident ppf id = pp_print_string ppf (ident_name id)
5252
(* Print a path *)
5353

5454
let ident_pervasives = Ident.create_persistent "Pervasives"
55+
let ident_stdlib = Ident.create_persistent "Stdlib"
5556
let printing_env = ref Env.empty
56-
let non_shadowed_pervasive = function
57+
let non_shadowed_pervasive_or_stdlib = function
5758
| Pdot (Pident id, s, _pos) as path -> (
58-
Ident.same id ident_pervasives
59+
(Ident.same id ident_pervasives || Ident.same id ident_stdlib)
5960
&&
6061
try Path.same path (Env.lookup_type (Lident s) !printing_env)
6162
with Not_found -> true)
6263
| _ -> false
6364

6465
let rec tree_of_path = function
6566
| Pident id -> Oide_ident (ident_name id)
66-
| Pdot (_, s, _pos) as path when non_shadowed_pervasive path -> Oide_ident s
67+
| Pdot (p, s, _pos) when String.starts_with (Path.name p) ~prefix:"Stdlib_" ->
68+
let path_name = Path.name p in
69+
let ident_without_stdlib_prefix =
70+
String.sub path_name 7 (String.length path_name - 7)
71+
in
72+
Oide_dot (Oide_ident ident_without_stdlib_prefix, s)
73+
| Pdot (_, s, _pos) as path when non_shadowed_pervasive_or_stdlib path ->
74+
Oide_ident s
6775
| Pdot (p, s, _pos) -> Oide_dot (tree_of_path p, s)
6876
| Papply (p1, p2) -> Oide_apply (tree_of_path p1, tree_of_path p2)
6977

7078
let rec path ppf = function
7179
| Pident id -> ident ppf id
72-
| Pdot (_, s, _pos) as path when non_shadowed_pervasive path ->
80+
| Pdot (_, s, _pos) as path when non_shadowed_pervasive_or_stdlib path ->
7381
pp_print_string ppf s
7482
| Pdot (p, s, _pos) ->
7583
path ppf p;
@@ -571,48 +579,8 @@ let reset_and_mark_loops_list tyl =
571579

572580
(* Disabled in classic mode when printing an unification error *)
573581

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-
613582
let rec tree_of_typexp sch ty =
614583
let ty = repr ty in
615-
let ty = remove_stdlib ty in
616584
let px = proxy ty in
617585
if List.mem_assq px !names && not (List.memq px !delayed) then
618586
let mark = is_non_gen sch ty in
@@ -1446,8 +1414,6 @@ let report_unification_error ppf env ?(unif = true) tr txt1 txt2 =
14461414
wrap_printing_env env (fun () -> unification_error env unif tr txt1 ppf txt2)
14471415

14481416
let super_type_expansion ~tag t ppf t' =
1449-
let t = remove_stdlib t in
1450-
let t' = remove_stdlib t' in
14511417
let tag = Format.String_tag tag in
14521418
if same_path t t' then (
14531419
Format.pp_open_stag ppf tag;

compiler/ml/printtyp.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ 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
7271
val report_unification_error :
7372
formatter ->
7473
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.t<'a>) => List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Stdlib_List.resi%22%2C36%2C0%5D)\n"}}
2+
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```"}}
33

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

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ Path withDate
4040
"label": "Date.makeWithYMD()",
4141
"kind": 12,
4242
"tags": [],
43-
"detail": "(~year: int, ~month: int, ~day: int) => t",
43+
"detail": "(~year: int, ~month: int, ~date: int) => t",
4444
"documentation": null,
4545
"insertText": "Date.makeWithYMD($0)",
4646
"insertTextFormat": 2
4747
}, {
4848
"label": "Date.makeWithYMDHM()",
4949
"kind": 12,
5050
"tags": [],
51-
"detail": "(\n ~year: int,\n ~month: int,\n ~day: int,\n ~hours: int,\n ~minutes: int,\n) => t",
51+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n) => t",
5252
"documentation": null,
5353
"insertText": "Date.makeWithYMDHM($0)",
5454
"insertTextFormat": 2
@@ -80,7 +80,7 @@ Path withDate
8080
"label": "Date.makeWithYMDHMSM()",
8181
"kind": 12,
8282
"tags": [],
83-
"detail": "(\n ~year: int,\n ~month: int,\n ~day: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n ~milliseconds: int,\n) => t",
83+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n ~milliseconds: int,\n) => t",
8484
"documentation": null,
8585
"insertText": "Date.makeWithYMDHMSM($0)",
8686
"insertTextFormat": 2
@@ -96,15 +96,15 @@ Path withDate
9696
"label": "Date.makeWithYMDHMS()",
9797
"kind": 12,
9898
"tags": [],
99-
"detail": "(\n ~year: int,\n ~month: int,\n ~day: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n) => t",
99+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n) => t",
100100
"documentation": null,
101101
"insertText": "Date.makeWithYMDHMS($0)",
102102
"insertTextFormat": 2
103103
}, {
104104
"label": "Date.makeWithYMDH()",
105105
"kind": 12,
106106
"tags": [],
107-
"detail": "(~year: int, ~month: int, ~day: int, ~hours: int) => t",
107+
"detail": "(~year: int, ~month: int, ~date: int, ~hours: int) => t",
108108
"documentation": null,
109109
"insertText": "Date.makeWithYMDH($0)",
110110
"insertTextFormat": 2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module type FT = {
6666
let make: (~name: string) => React.element
6767
}
6868
}
69-
module NormaList = Stdlib.List
69+
module NormaList = List
7070
module BeltList = Belt.List
7171
module type MT2 = ModTyp
7272
module rec RM: ModTyp

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.t<'a>, 'a => 'b) => List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Stdlib_List.resi%22%2C36%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"}}
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"}}
99

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

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

0 commit comments

Comments
 (0)