Skip to content

Commit e612a20

Browse files
committed
Add support for detailed info (jump-to-def, hover) on a signature.
Fixes #204
1 parent 3644354 commit e612a20

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

analysis/src/ProcessCmt.ml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,8 @@ struct
10731073
| _ -> ()
10741074
end
10751075

1076-
let forStructureItems ~(file : File.t) items parts =
1076+
let forStructureItems ~(file : File.t) (items : Typedtree.structure_item list)
1077+
parts =
10771078
let extra = extraForFile ~file in
10781079
let extent = itemsExtent items in
10791080
let extent =
@@ -1109,8 +1110,46 @@ let forStructureItems ~(file : File.t) items parts =
11091110
| Partial_structure _ | Partial_structure_item _ -> ());
11101111
extra
11111112

1113+
let forSignatureItems ~(file : File.t) (items : Typedtree.signature_item list)
1114+
parts =
1115+
let extra = extraForFile ~file in
1116+
let extent = sigItemsExtent items in
1117+
let extent =
1118+
{
1119+
extent with
1120+
loc_end =
1121+
{
1122+
extent.loc_end with
1123+
pos_lnum = extent.loc_end.pos_lnum + 1000000;
1124+
pos_cnum = extent.loc_end.pos_cnum + 100000000;
1125+
};
1126+
}
1127+
in
1128+
(* TODO look through parts and extend the extent *)
1129+
let module Iter = TypedtreeIter.MakeIterator (F (struct
1130+
let scopeExtent = ref [extent]
1131+
1132+
let extra = extra
1133+
1134+
let file = file
1135+
end)) in
1136+
List.iter Iter.iter_signature_item items;
1137+
(* Log.log("Parts " ++ string_of_int(Array.length(parts))); *)
1138+
parts
1139+
|> Array.iter (fun part ->
1140+
match part with
1141+
| Cmt_format.Partial_signature str -> Iter.iter_signature str
1142+
| Partial_signature_item str -> Iter.iter_signature_item str
1143+
| Partial_expression expression -> Iter.iter_expression expression
1144+
| Partial_pattern pattern -> Iter.iter_pattern pattern
1145+
| Partial_class_expr class_expr -> Iter.iter_class_expr class_expr
1146+
| Partial_module_type module_type -> Iter.iter_module_type module_type
1147+
| Partial_structure _ | Partial_structure_item _ -> ());
1148+
extra
1149+
11121150
let extraForCmt ~file ({cmt_annots} : Cmt_format.cmt_infos) =
11131151
match cmt_annots with
1152+
| Implementation structure -> forStructureItems ~file structure.str_items [||]
11141153
| Partial_implementation parts ->
11151154
let items =
11161155
parts |> Array.to_list
@@ -1123,8 +1162,18 @@ let extraForCmt ~file ({cmt_annots} : Cmt_format.cmt_infos) =
11231162
|> List.concat
11241163
in
11251164
forStructureItems ~file items parts
1126-
| Implementation structure -> forStructureItems ~file structure.str_items [||]
1127-
| Partial_interface _ | Interface _ -> forStructureItems ~file [] [||]
1165+
| Interface signature -> forSignatureItems ~file signature.sig_items [||]
1166+
| Partial_interface parts ->
1167+
let items =
1168+
parts |> Array.to_list
1169+
|> Utils.filterMap (fun (p : Cmt_format.binary_part) ->
1170+
match p with
1171+
| Partial_signature s -> Some s.sig_items
1172+
| Partial_signature_item str -> Some [str]
1173+
| _ -> None)
1174+
|> List.concat
1175+
in
1176+
forSignatureItems ~file items parts
11281177
| _ -> forStructureItems ~file [] [||]
11291178

11301179
let fullForCmt ~moduleName ~package ~uri cmt =

analysis/tests/src/expected/Jsx.resi.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hover tests/src/Jsx.resi 1:4
2-
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}
2+
{"contents": "```rescript\nReact.componentLike<{\"first\": string}, React.element>\n```\n\n```rescript\ntype componentLike<'props, 'return> = 'props => 'return\n```"}
33

44
Hover tests/src/Jsx.resi 4:4
55
{"contents": "```rescript\nint\n```"}

0 commit comments

Comments
 (0)