File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -319,23 +319,27 @@ let lookup_type_expr = (~idx, type_exprs) => {
319319 Option . bind(type_exprs, te => List . nth_opt(te, idx));
320320};
321321
322+ let saved_comments = Hashtbl . create(64 );
323+
322324let get_comments_from_loc = (loc: Grain_parsing . Location . t ) => {
323325 open Compile ;
324326
325- let comments =
326- switch (
327- compile_file(
328- ~is_root_file= true ,
329- ~hook= stop_after_parse,
330- loc. loc_start. pos_fname,
331- )
332- ) {
333- | exception exn => []
334- | {cstate_desc: Parsed (parsed_program )} => parsed_program. comments
335- | _ => failwith ("Invalid compilation state" )
336- };
327+ let file = loc. loc_start. pos_fname;
337328
338- Comments . to_ordered(comments);
329+ switch (Hashtbl . find_opt(saved_comments, file)) {
330+ | Some (comments ) => comments
331+ | None =>
332+ let comments =
333+ switch (compile_file(~is_root_file= true , ~hook= stop_after_parse, file)) {
334+ | exception exn => []
335+ | {cstate_desc: Parsed (parsed_program )} => parsed_program. comments
336+ | _ => failwith ("Invalid compilation state" )
337+ };
338+
339+ let ordered = Comments . to_ordered(comments);
340+ Hashtbl . add(saved_comments, file, ordered);
341+ ordered;
342+ };
339343};
340344
341345let attr_name = attr => {
You can’t perform that action at this time.
0 commit comments