Skip to content

Commit 5bc3194

Browse files
cknittclaude
andcommitted
Link signature help type definitions to their declaring file
Codex review on #9084: signature help built its Type definition link from the caller's file, so for a type of an applied functor from another file it pointed into the caller. It now takes the file from the type's declaration, as hover does; the link function requires it, so no caller can fall back to the wrong file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3 Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent c4cc7a1 commit 5bc3194

5 files changed

Lines changed: 45 additions & 12 deletions

File tree

‎analysis/src/hover.ml‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,12 @@ let expand_types ~state ~file ~package ~supports_markdown_links typ =
149149
else (
150150
types_seen := String_set.add type_id !types_seen;
151151
true))
152-
|> List.map (fun {decl; env; loc; path; uri} ->
152+
|> List.map (fun {decl; loc; path; uri} ->
153153
let link_to_type_definition_str =
154154
if
155155
supports_markdown_links
156156
&& not (is_inline_record_definition decl path)
157-
then
158-
Markdown.go_to_definition_text ~uri ~env
159-
~pos:loc.Warnings.loc_start ()
157+
then Markdown.go_to_definition_text ~uri ~pos:loc.Warnings.loc_start
160158
else ""
161159
in
162160
Markdown.divider

‎analysis/src/markdown.ml‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ let make_goto_command link =
88
Printf.sprintf "[%s](%s#L%d,%d)" link.label link.file (link.start_pos.line + 1)
99
(link.start_pos.character + 1)
1010

11-
let go_to_definition_text ?uri ~env ~pos () =
11+
let go_to_definition_text ~uri ~pos =
1212
let start_line, start_col = Pos.of_lexing pos in
13-
let uri =
14-
match uri with
15-
| Some uri -> uri
16-
| None -> env.Shared_types.Query_env.file.uri
17-
in
1813
"\nGo to: "
1914
^ make_goto_command
2015
{

‎analysis/src/signature_help.ml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ let docs_for_label type_expr ~file ~state ~package ~supports_markdown_links =
99
let type_names = types |> List.map (fun {Hover.name} -> name) in
1010
let type_definitions =
1111
types
12-
|> List.map (fun {Hover.decl; name; env; loc; path} ->
12+
|> List.map (fun {Hover.decl; name; loc; path; uri} ->
1313
let link_to_type_definition_str =
1414
if supports_markdown_links then
15-
Markdown.go_to_definition_text ~env ~pos:loc.Warnings.loc_start ()
15+
Markdown.go_to_definition_text ~uri ~pos:loc.Warnings.loc_start
1616
else ""
1717
in
1818
(* Since printing the whole name via its path can get quite long, and

‎tests/analysis_tests/tests/src/AppliedFunctorUse.res‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ let s = StrSet.add([], "a")
88

99
let t: StrSet.t = []
1010
// ^hov
11+
12+
// let _ = StrSet.add(
13+
// ^she

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,40 @@ Hover src/AppliedFunctorUse.res 8:14
1515
}
1616
}
1717

18+
Signature help src/AppliedFunctorUse.res 11:22
19+
pos_cursor:[11:21] pos_no_white:[11:20] Found expr:[11:11->11:22]
20+
Pexp_apply ...[11:11->11:21] (...[14:0->11:22])
21+
pos_cursor:[11:21] pos_no_white:[11:20] Found expr:[11:11->11:21]
22+
Pexp_ident StrSet.add:[11:11->11:21]
23+
Completable: Cpath Value[StrSet, add]
24+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
25+
Resolved opens 1 Stdlib
26+
ContextPath Value[StrSet, add]
27+
Path StrSet.add
28+
arg_at_cursor: unlabelled<0>
29+
extracted params:
30+
[t, string]
31+
{
32+
"activeParameter": 0,
33+
"activeSignature": 0,
34+
"signatures": [
35+
{
36+
"activeParameter": 0,
37+
"label": "(t, string) => array<string>",
38+
"parameters": [
39+
{
40+
"documentation": {
41+
"kind": "markdown",
42+
"value": "```rescript\ntype t = array<string>\n```\nGo to: [Type definition](AppliedFunctor.res#L7,3)"
43+
},
44+
"label": [ 1, 2 ]
45+
},
46+
{
47+
"documentation": { "kind": "markdown", "value": "" },
48+
"label": [ 4, 10 ]
49+
}
50+
]
51+
}
52+
]
53+
}
54+

0 commit comments

Comments
 (0)