@@ -756,78 +756,6 @@ let getCompletionsForPath ~debug ~opens ~full ~pos ~exact ~scope
756756 findAllCompletions ~env ~prefix ~exact ~names Used ~completion Context
757757 | None -> [] ))
758758
759- (* Collect exception constructor names from cmt infos. *)
760- let exceptions_from_cmt_infos (infos : Cmt_format.cmt_infos ) :
761- (string * bool ) list =
762- let by_name : (string, bool) Hashtbl.t = Hashtbl. create 16 in
763- let add_ext (ext : Typedtree.extension_constructor ) : unit =
764- let name = ext.ext_name.txt in
765- let hasArgs =
766- match ext.ext_kind with
767- | Text_decl (Cstr_tuple args , _ret ) -> args <> []
768- | Text_decl (Cstr_record fields , _ret ) -> fields <> []
769- | Text_rebind _ -> true
770- in
771- let prev =
772- match Hashtbl. find_opt by_name name with
773- | Some b -> b
774- | None -> false
775- in
776- Hashtbl. replace by_name name (prev || hasArgs)
777- in
778- (* Only collect top-level exception declarations (Tstr_exception/Tsig_exception).
779- Avoid picking up exceptions from Texp_letexception by tracking context. *)
780- let in_toplevel_exception = ref false in
781- let module Iter = TypedtreeIter. MakeIterator (struct
782- include TypedtreeIter. DefaultIteratorArgument
783-
784- let enter_structure_item (item : Typedtree.structure_item ) =
785- (match item.str_desc with
786- | Tstr_exception _ -> in_toplevel_exception := true
787- | _ -> () );
788- ()
789-
790- let leave_structure_item (_ : Typedtree.structure_item ) =
791- in_toplevel_exception := false
792-
793- let enter_signature_item (item : Typedtree.signature_item ) =
794- (match item.sig_desc with
795- | Tsig_exception _ -> in_toplevel_exception := true
796- | _ -> () );
797- ()
798-
799- let leave_signature_item (_ : Typedtree.signature_item ) =
800- in_toplevel_exception := false
801-
802- let enter_extension_constructor (ext : Typedtree.extension_constructor ) =
803- if ! in_toplevel_exception then add_ext ext
804- end ) in
805- let () =
806- match infos.cmt_annots with
807- | Cmt_format. Implementation s -> Iter. iter_structure s
808- | Interface s -> Iter. iter_signature s
809- | Partial_implementation parts ->
810- Array. iter
811- (function
812- | Cmt_format. Partial_structure s -> Iter. iter_structure s
813- | Partial_structure_item si -> Iter. iter_structure_item si
814- | Partial_signature s -> Iter. iter_signature s
815- | Partial_signature_item si -> Iter. iter_signature_item si
816- | _ -> () )
817- parts
818- | Partial_interface parts ->
819- Array. iter
820- (function
821- | Cmt_format. Partial_structure s -> Iter. iter_structure s
822- | Partial_structure_item si -> Iter. iter_structure_item si
823- | Partial_signature s -> Iter. iter_signature s
824- | Partial_signature_item si -> Iter. iter_signature_item si
825- | _ -> () )
826- parts
827- | _ -> ()
828- in
829- Hashtbl. fold (fun name hasArgs acc -> (name, hasArgs) :: acc) by_name []
830-
831759(* Predefined Stdlib/Pervasives exceptions. *)
832760let predefined_exceptions : (string * bool) list =
833761 [
@@ -840,17 +768,15 @@ let predefined_exceptions : (string * bool) list =
840768 ]
841769
842770let completionsForThrow ~(env : QueryEnv.t ) ~full =
843- let exn_typ = Ctype. newconstr Predef. path_exn [] in
771+ let exn_typ = Predef. type_exn in
844772 let names_from_cmt =
845773 let moduleName = env.file.moduleName in
846774 match Hashtbl. find_opt full.package.pathsForModule moduleName with
847775 | None -> []
848- | Some paths -> (
776+ | Some paths ->
849777 let uri = getUri paths in
850778 let cmt_path = getCmtPath ~uri paths in
851- match Shared. tryReadCmt cmt_path with
852- | None -> []
853- | Some infos -> exceptions_from_cmt_infos infos)
779+ ProcessCmt. exceptionsForCmt ~cmt: cmt_path
854780 in
855781 let all = names_from_cmt @ predefined_exceptions in
856782 all
0 commit comments