Skip to content

Commit 8840411

Browse files
cknittclaude
andcommitted
Show unit parameters of a multi-parameter functor on hover
Codex review on #9083: a unit parameter showed as nothing, so hover on `(P: Primitive, ()) => ...` read `(P: Primitive, ) => ...`. It shows as `()` now, and a functor with only a unit parameter as `() => ...`, as the formatter prints them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent af0fdff commit 8840411

4 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎analysis/src/hover.ml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let show_module_top_level ?(functor_params = []) ~docstring ~is_type ~name
2424
^ (if is_type then "type " ^ name ^ " = " else name ^ ": ")
2525
^ (match functor_params with
2626
| [] -> ""
27+
| ["()"] -> "() => "
2728
| params -> "(" ^ String.concat ", " params ^ ") => ")
2829
^ "{" ^ "\n" ^ contents ^ "\n}")
2930
in

‎analysis/src/process_cmt.ml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ let module_type_to_string (mty : Types.module_type) =
5050
| Mty_functor _ -> "{...}"
5151

5252
(* A functor parameter as hover shows it, such as [O: Ord]; a generative
53-
functor's [*] parameter shows as nothing, giving [() => ...]. *)
53+
functor's [*] parameter shows as [()]. *)
5454
let functor_param ~name (mty : Types.module_type option) =
5555
match (name, mty) with
56-
| "*", _ -> ""
56+
| "*", _ -> "()"
5757
| _, None -> name
5858
| _, Some mty -> name ^ ": " ^ module_type_to_string mty
5959

‎tests/analysis_tests/tests/src/HoverFunctor.res‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,30 @@ module Counter = () => {
3838
// ^hov
3939
let count = ref(0)
4040
}
41+
42+
module type Primitive = {
43+
type t
44+
}
45+
46+
module Gen = (P: Primitive, ()) => {
47+
// ^hov
48+
type t = P.t
49+
}
50+
51+
module GenFirst = ((), P: Primitive) => {
52+
// ^hov
53+
type t = P.t
54+
}
55+
56+
module Curried = (A: Ord) => (B: Ord) => {
57+
// ^hov
58+
type t = (A.t, B.t)
59+
}
60+
61+
module GenCurried = () => (P: Primitive) => {
62+
// ^hov
63+
type t = P.t
64+
}
65+
66+
module GenApplied = Gen(IntOrd)
67+
// ^hov

‎tests/analysis_tests/tests/src/expected/HoverFunctor.res.txt‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,43 @@ Hover src/HoverFunctor.res 36:9
4646
}
4747
}
4848

49+
Hover src/HoverFunctor.res 45:7
50+
{
51+
"contents": {
52+
"kind": "markdown",
53+
"value": "```rescript\nmodule Gen: (P: Primitive, ()) => {\n type t = P.t\n}\n```"
54+
}
55+
}
56+
57+
Hover src/HoverFunctor.res 50:9
58+
{
59+
"contents": {
60+
"kind": "markdown",
61+
"value": "```rescript\nmodule GenFirst: ((), P: Primitive) => {\n type t = P.t\n}\n```"
62+
}
63+
}
64+
65+
Hover src/HoverFunctor.res 55:9
66+
{
67+
"contents": {
68+
"kind": "markdown",
69+
"value": "```rescript\nmodule Curried: (A: Ord, B: Ord) => {\n type t = (A.t, B.t)\n}\n```"
70+
}
71+
}
72+
73+
Hover src/HoverFunctor.res 60:9
74+
{
75+
"contents": {
76+
"kind": "markdown",
77+
"value": "```rescript\nmodule GenCurried: ((), P: Primitive) => {\n type t = P.t\n}\n```"
78+
}
79+
}
80+
81+
Hover src/HoverFunctor.res 65:8
82+
{
83+
"contents": {
84+
"kind": "markdown",
85+
"value": "```rescript\nmodule GenApplied: () => {\n type t = IntOrd.t\n}\n```"
86+
}
87+
}
88+

0 commit comments

Comments
 (0)