@@ -35,16 +35,18 @@ open Typedtree
3535open Browse_raw
3636open Browse_tree
3737
38- let id_of_patt = function
39- | { pat_desc = Tpat_var (id , _ , _ ); _ } -> Some id
38+ let name_of_patt = function
39+ | { pat_desc = Tpat_var (_ , name , _ ); _ } -> Some name
4040 | _ -> None
4141
42- let mk ?(children = [] ) ~location ~deprecated outline_kind outline_type id =
42+ let mk ?(children = [] ) ~location ~deprecated outline_kind outline_type
43+ (name : string Location.loc ) =
4344 { Query_protocol. outline_kind;
4445 outline_type;
4546 location;
47+ selection = name.loc;
4648 children;
47- outline_name = Ident. name id ;
49+ outline_name = name.txt ;
4850 deprecated
4951 }
5052
@@ -69,38 +71,38 @@ let rec summarize node =
6971 in
7072 let deprecated = Type_utils. is_deprecated vb.vb_attributes in
7173 begin
72- match id_of_patt vb.vb_pat with
74+ match name_of_patt vb.vb_pat with
7375 | None -> None
74- | Some ident ->
76+ | Some name ->
7577 let typ = outline_type ~env: node.t_env vb.vb_pat.pat_type in
76- Some (mk ~children ~location ~deprecated `Value typ ident )
78+ Some (mk ~children ~location ~deprecated `Value typ name )
7779 end
7880 | Value_description vd ->
7981 let deprecated = Type_utils. is_deprecated vd.val_attributes in
8082 let typ = outline_type ~env: node.t_env vd.val_val.val_type in
81- Some (mk ~location ~deprecated `Value typ vd.val_id )
83+ Some (mk ~location ~deprecated `Value typ vd.val_name )
8284 | Module_declaration md ->
8385 let children = get_mod_children node in
8486 begin
85- match md.md_id with
86- | None -> None
87- | Some id ->
87+ match md.md_name with
88+ | { txt = None ; _ } -> None
89+ | { txt = Some txt ; loc } ->
8890 let deprecated = Type_utils. is_deprecated md.md_attributes in
89- Some (mk ~children ~location ~deprecated `Module None id )
91+ Some (mk ~children ~location ~deprecated `Module None { txt; loc } )
9092 end
9193 | Module_binding mb ->
9294 let children = get_mod_children node in
9395 begin
94- match mb.mb_id with
95- | None -> None
96- | Some id ->
96+ match mb.mb_name with
97+ | { txt = None ; _ } -> None
98+ | { txt = Some txt ; loc } ->
9799 let deprecated = Type_utils. is_deprecated mb.mb_attributes in
98- Some (mk ~children ~location ~deprecated `Module None id )
100+ Some (mk ~children ~location ~deprecated `Module None { txt; loc } )
99101 end
100102 | Module_type_declaration mtd ->
101103 let children = get_mod_children node in
102104 let deprecated = Type_utils. is_deprecated mtd.mtd_attributes in
103- Some (mk ~deprecated ~children ~location `Modtype None mtd.mtd_id )
105+ Some (mk ~deprecated ~children ~location `Modtype None mtd.mtd_name )
104106 | Type_declaration td ->
105107 let children =
106108 List. concat_map (Lazy. force node.t_children) ~f: (fun child ->
@@ -110,15 +112,15 @@ let rec summarize node =
110112 match x.t_node with
111113 | Constructor_declaration c ->
112114 let deprecated = Type_utils. is_deprecated c.cd_attributes in
113- mk `Constructor None c.cd_id ~deprecated ~location: c.cd_loc
115+ mk `Constructor None c.cd_name ~deprecated ~location: c.cd_loc
114116 | Label_declaration ld ->
115117 let deprecated = Type_utils. is_deprecated ld.ld_attributes in
116- mk `Label None ld.ld_id ~deprecated ~location: ld.ld_loc
118+ mk `Label None ld.ld_name ~deprecated ~location: ld.ld_loc
117119 | _ -> assert false (* ! *) )
118120 | _ -> [] )
119121 in
120122 let deprecated = Type_utils. is_deprecated td.typ_attributes in
121- Some (mk ~children ~location ~deprecated `Type None td.typ_id )
123+ Some (mk ~children ~location ~deprecated `Type None td.typ_name )
122124 | Type_extension te ->
123125 let name = Path. name te.tyext_path in
124126 let children =
@@ -132,65 +134,58 @@ let rec summarize node =
132134 outline_kind = `Type ;
133135 outline_type = None ;
134136 location;
137+ selection = te.tyext_txt.loc;
135138 children;
136139 deprecated
137140 }
138141 | Extension_constructor ec ->
139142 let deprecated = Type_utils. is_deprecated ec.ext_attributes in
140- Some (mk ~location `Exn None ec.ext_id ~deprecated )
143+ Some (mk ~location `Exn None ec.ext_name ~deprecated )
141144 | Class_declaration cd ->
142145 let children =
143146 List. concat_map (Lazy. force node.t_children) ~f: get_class_elements
144147 in
145148 let deprecated = Type_utils. is_deprecated cd.ci_attributes in
146- Some (mk ~children ~location `Class None cd.ci_id_class_type ~deprecated )
149+ Some (mk ~children ~location `Class None cd.ci_id_name ~deprecated )
147150 | Class_type_declaration ctd ->
148151 let children =
149152 List. concat_map (Lazy. force node.t_children) ~f: get_class_elements
150153 in
151154 let deprecated = Type_utils. is_deprecated ctd.ci_attributes in
152- Some
153- (mk ~children ~location `ClassType None ctd.ci_id_class_type ~deprecated )
155+ Some (mk ~children ~location `ClassType None ctd.ci_id_name ~deprecated )
154156 | _ -> None
155157
156158and get_val_elements node =
157159 match node.t_node with
158160 | Expression _ ->
159161 List. concat_map (Lazy. force node.t_children) ~f: get_val_elements
160- | Value_binding vb ->
161- let children =
162- List. concat_map (Lazy. force node.t_children) ~f: get_val_elements
163- in
164- let deprecated = Type_utils. is_deprecated vb.vb_attributes in
165- begin
166- match id_of_patt vb.vb_pat with
167- | None -> []
168- | Some ident ->
169- [ mk ~children ~location: node.t_loc ~deprecated `Value None ident ]
170- end
171162 | Class_expr _ | Class_structure _ -> get_class_elements node
172- | _ -> []
163+ | _ -> Option. to_list (summarize node)
173164
174165and get_class_elements node =
175166 match node.t_node with
176167 | Class_expr _ ->
177168 List. concat_map (Lazy. force node.t_children) ~f: get_class_elements
169+ | Class_field cf ->
170+ let children =
171+ List. concat_map (Lazy. force node.t_children) ~f: get_class_elements
172+ in
173+ cf.cf_desc |> get_class_field_desc_infos
174+ |> Option. map ~f: (fun (str_loc , outline_kind ) ->
175+ let deprecated = Type_utils. is_deprecated cf.cf_attributes in
176+ { Query_protocol. outline_name = str_loc.Location. txt;
177+ outline_kind;
178+ outline_type = None ;
179+ location = cf.cf_loc;
180+ selection = str_loc.loc;
181+ children;
182+ deprecated
183+ })
184+ |> Option. to_list
185+ | Class_field_kind _ ->
186+ List. concat_map (Lazy. force node.t_children) ~f: get_val_elements
178187 | Class_structure _ ->
179- List. filter_map (Lazy. force node.t_children) ~f: (fun child ->
180- match child.t_node with
181- | Class_field cf -> begin
182- cf.cf_desc |> get_class_field_desc_infos
183- |> Option. map ~f: (fun (str_loc , outline_kind , children ) ->
184- let deprecated = Type_utils. is_deprecated cf.cf_attributes in
185- { Query_protocol. outline_name = str_loc.Location. txt;
186- outline_kind;
187- outline_type = None ;
188- location = str_loc.Location. loc;
189- children;
190- deprecated
191- })
192- end
193- | _ -> None )
188+ List. concat_map (Lazy. force node.t_children) ~f: get_class_elements
194189 | Class_type { cltyp_desc = Tcty_signature { csig_fields; _ } ; _ } ->
195190 List. filter_map csig_fields ~f: (fun field ->
196191 get_class_signature_field_desc_infos field.ctf_desc
@@ -200,49 +195,18 @@ and get_class_elements node =
200195 outline_kind;
201196 outline_type = None ;
202197 location = field.ctf_loc;
198+ selection = field.ctf_loc;
203199 (* TODO: could we have more precised location information? *)
204200 children = [] ;
205201 deprecated
206202 }))
207203 | _ -> []
208204
209205and get_class_field_desc_infos = function
210- | Typedtree. Tcf_val (str_loc , _ , _ , field_kind , _ ) ->
211- Some (str_loc, `Value , get_class_field_kind_elements field_kind)
212- | Typedtree. Tcf_method (str_loc , _ , field_kind ) ->
213- Some (str_loc, `Method , get_class_field_kind_elements field_kind)
206+ | Typedtree. Tcf_val (str_loc , _ , _ , _field_kind , _ ) -> Some (str_loc, `Value )
207+ | Typedtree. Tcf_method (str_loc , _ , _field_kind ) -> Some (str_loc, `Method )
214208 | _ -> None
215209
216- and get_class_field_kind_elements = function
217- | Tcfk_virtual _ -> []
218- | Tcfk_concrete (_ , expr ) -> get_expr_elements expr
219-
220- and get_expr_elements expr =
221- match expr.exp_desc with
222- | Texp_let (_ , vbs , expr ) ->
223- List. filter_map vbs ~f: (fun vb ->
224- id_of_patt vb.vb_pat
225- |> Option. map ~f: (fun ident ->
226- let children = get_expr_elements vb.vb_expr in
227- let deprecated = Type_utils. is_deprecated vb.vb_attributes in
228-
229- mk ~children ~location: vb.vb_loc ~deprecated `Value None ident))
230- @ get_expr_elements expr
231- | Texp_object ({ cstr_fields; _ } , _ ) ->
232- List. filter_map cstr_fields ~f: (fun field ->
233- field.cf_desc |> get_class_field_desc_infos
234- |> Option. map ~f: (fun (str_loc , outline_kind , children ) ->
235- let deprecated = Type_utils. is_deprecated field.cf_attributes in
236- { Query_protocol. outline_name = str_loc.Location. txt;
237- outline_kind;
238- outline_type = None ;
239- location = str_loc.Location. loc;
240- children;
241- deprecated
242- }))
243- | Texp_function (_ , Tfunction_body expr ) -> get_expr_elements expr
244- | _ -> []
245-
246210and get_mod_children node =
247211 List. concat_map (Lazy. force node.t_children) ~f: remove_mod_indir
248212
0 commit comments