Skip to content

Add support for detailed info (jump-to-def, hover) on a signature. #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ let hover ~path ~line ~col =
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> Protocol.null
| Some ({file; extra} as full) -> (
| Some ({file} as full) -> (
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
match References.locItemForPos ~extra pos with
match References.locItemForPos ~full pos with
| None -> Protocol.null
| Some locItem -> (
let isModule =
Expand Down Expand Up @@ -83,10 +83,10 @@ let definition ~path ~line ~col =
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> Protocol.null
| Some ({file; extra} as full) -> (
| Some ({file} as full) -> (
let pos = Utils.protocolLineColToCmtLoc ~line ~col in

match References.locItemForPos ~extra pos with
match References.locItemForPos ~full pos with
| None -> Protocol.null
| Some locItem -> (
let isModule =
Expand Down Expand Up @@ -118,9 +118,9 @@ let references ~path ~line ~col =
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> Protocol.null
| Some ({extra} as full) -> (
| Some full -> (
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
match References.locItemForPos ~extra pos with
match References.locItemForPos ~full pos with
| None -> Protocol.null
| Some locItem ->
let allReferences = References.allReferencesForLocItem ~full locItem in
Expand Down
55 changes: 52 additions & 3 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,8 @@ struct
| _ -> ()
end

let forStructureItems ~(file : File.t) items parts =
let forStructureItems ~(file : File.t) (items : Typedtree.structure_item list)
parts =
let extra = extraForFile ~file in
let extent = itemsExtent items in
let extent =
Expand Down Expand Up @@ -1109,8 +1110,46 @@ let forStructureItems ~(file : File.t) items parts =
| Partial_structure _ | Partial_structure_item _ -> ());
extra

let forSignatureItems ~(file : File.t) (items : Typedtree.signature_item list)
parts =
let extra = extraForFile ~file in
let extent = sigItemsExtent items in
let extent =
{
extent with
loc_end =
{
extent.loc_end with
pos_lnum = extent.loc_end.pos_lnum + 1000000;
pos_cnum = extent.loc_end.pos_cnum + 100000000;
};
}
in
(* TODO look through parts and extend the extent *)
let module Iter = TypedtreeIter.MakeIterator (F (struct
let scopeExtent = ref [extent]

let extra = extra

let file = file
end)) in
List.iter Iter.iter_signature_item items;
(* Log.log("Parts " ++ string_of_int(Array.length(parts))); *)
parts
|> Array.iter (fun part ->
match part with
| Cmt_format.Partial_signature str -> Iter.iter_signature str
| Partial_signature_item str -> Iter.iter_signature_item str
| Partial_expression expression -> Iter.iter_expression expression
| Partial_pattern pattern -> Iter.iter_pattern pattern
| Partial_class_expr class_expr -> Iter.iter_class_expr class_expr
| Partial_module_type module_type -> Iter.iter_module_type module_type
| Partial_structure _ | Partial_structure_item _ -> ());
extra

let extraForCmt ~file ({cmt_annots} : Cmt_format.cmt_infos) =
match cmt_annots with
| Implementation structure -> forStructureItems ~file structure.str_items [||]
| Partial_implementation parts ->
let items =
parts |> Array.to_list
Expand All @@ -1123,8 +1162,18 @@ let extraForCmt ~file ({cmt_annots} : Cmt_format.cmt_infos) =
|> List.concat
in
forStructureItems ~file items parts
| Implementation structure -> forStructureItems ~file structure.str_items [||]
| Partial_interface _ | Interface _ -> forStructureItems ~file [] [||]
| Interface signature -> forSignatureItems ~file signature.sig_items [||]
| Partial_interface parts ->
let items =
parts |> Array.to_list
|> Utils.filterMap (fun (p : Cmt_format.binary_part) ->
match p with
| Partial_signature s -> Some s.sig_items
| Partial_signature_item str -> Some [str]
| _ -> None)
|> List.concat
in
forSignatureItems ~file items parts
| _ -> forStructureItems ~file [] [||]

let fullForCmt ~moduleName ~package ~uri cmt =
Expand Down
7 changes: 5 additions & 2 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ let checkPos (line, char)
let locItemsForPos ~extra pos =
extra.locItems |> List.filter (fun {loc; locType = _} -> checkPos pos loc)

let locItemForPos ~extra pos =
let locItems = locItemsForPos ~extra pos in
let locItemForPos ~full pos =
let locItems = locItemsForPos ~extra:full.extra pos in
match locItems with
| _ :: _ :: _ :: l :: _ when full.file.uri |> Uri2.isInterface ->
(* heuristic for makeProps in interface files *)
Some l
| [({locType = Typed (_, LocalReference _)} as li1); li3]
when li1.loc = li3.loc ->
(* JSX and compiler combined:
Expand Down
3 changes: 0 additions & 3 deletions analysis/tests/src/expected/A.res.txt

This file was deleted.