diff --git a/analysis/src/Commands.ml b/analysis/src/Commands.ml index 021ec267a..37b7192ac 100644 --- a/analysis/src/Commands.ml +++ b/analysis/src/Commands.ml @@ -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 = @@ -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 = @@ -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 diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml index 6bfb9811e..a60f1e87f 100644 --- a/analysis/src/ProcessCmt.ml +++ b/analysis/src/ProcessCmt.ml @@ -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 = @@ -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 @@ -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 = diff --git a/analysis/src/References.ml b/analysis/src/References.ml index 129eeb0a3..43207325f 100644 --- a/analysis/src/References.ml +++ b/analysis/src/References.ml @@ -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: diff --git a/analysis/tests/src/expected/A.res.txt b/analysis/tests/src/expected/A.res.txt deleted file mode 100644 index 75bf4748b..000000000 --- a/analysis/tests/src/expected/A.res.txt +++ /dev/null @@ -1,3 +0,0 @@ -Hover tests/src/A.res 4:7 -{"contents": "```rescript\nmodule JsLogger = {\n let log: string => unit\n}\n```"} -