package merlin-lib
Merlin's libraries
Install
Dune Dependency
Authors
Maintainers
Sources
merlin-5.5-503.tbz
sha256=67da3b34f2fea07678267309f61da4a2c6f08298de0dc59655b8d30fd8269af1
sha512=1fb3b5180d36aa82b82a319e15b743b802b6888f0dc67645baafdb4e18dfc23a7b90064ec9bc42f7424061cf8cde7f8839178d8a8537bf4596759f3ff4891873
doc/src/merlin-lib.analysis/refactor_open.ml.html
Source file refactor_open.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
open Std (** [qual_or_unqual_path mode ~open_lident ~open_path node_path node_lid] if mode is `Unqualify - returns [node_lid] or [node_lid] with prefix [open_lident] cut off, whichever is shorter `Qualify - returns [node_path] with its prefix equal to [open_lident] Returns [None] if [node_lid] doesn't need changes. Note: by "prefix" we mean the leftmost consecutive part of a longident or a path. *) let qual_or_unqual_path mode ~open_lident ~open_path node_path node_lid = let open_lid_head = Longident.head open_lident in let node_lid_head = Longident.head node_lid in let rec make_new_node_lid acc (p : Path.t) = match p with | Pident ident -> Ident.name ident :: acc | Pdot (path', s) when mode = `Unqualify && (Path.same open_path path' || String.equal s node_lid_head (* unqualify shouldn't enlarge lident *)) -> s :: acc | Pdot (_, s) when mode = `Qualify && s = open_lid_head -> s :: acc | Pdot (path', s) -> make_new_node_lid (s :: acc) path' | _ -> raise Not_found in let same_longident node_lid_head new_node_lid = (* this works because [make_new_node_lid] changes only prefix of a longident *) String.equal node_lid_head (List.hd new_node_lid) in match make_new_node_lid [] node_path with | new_node_lid when not (same_longident node_lid_head new_node_lid) -> Some (String.concat ~sep:"." new_node_lid) | _ | (exception Not_found) -> None let get_rewrites ~mode typer pos = match Mbrowse.select_open_node (Mtyper.node_at typer pos) with | None | Some (_, _, []) -> [] | Some (open_path, open_lident, (_, node) :: _) -> let paths_and_lids = Browse_tree.all_occurrences_of_prefix open_path node in List.filter_map paths_and_lids ~f:(fun ({ Location.txt = path; loc }, lid) -> if loc.Location.loc_ghost || Location_aux.compare_pos pos loc > 0 then None else qual_or_unqual_path mode ~open_lident ~open_path path lid |> Option.map ~f:(fun new_lid -> (new_lid, loc))) |> List.sort_uniq ~cmp:(fun (_, l1) (_, l2) -> Location_aux.compare l1 l2)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>