Skip to content

Commit 79e7e1e

Browse files
committed
tools: refactor
1 parent 2de0c17 commit 79e7e1e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

tools/bin/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let main () =
4141
| Some "true" -> Analysis.Cfg.isDocGenFromCompiler := true
4242
| _ -> ()
4343
in
44-
logAndExit (Tools.extractDocs ~path ~debug:false)
44+
logAndExit (Tools.extractDocs ~entryPointFile:path ~debug:false)
4545
| _ -> logAndExit (Error docHelp))
4646
| "reanalyze" :: _ ->
4747
let len = Array.length Sys.argv in

tools/src/tools.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,15 @@ let findRelativePath ~rootPath ~path =
302302

303303
let getSource ~rootPath ({loc_start} : Location.t) =
304304
let line, col = Pos.ofLexing loc_start in
305-
306305
let filepath = findRelativePath ~rootPath ~path:loc_start.pos_fname in
307-
308306
{filepath; line = line + 1; col = col + 1}
309307

310-
let extractDocs ~path ~debug =
308+
let extractDocs ~entryPointFile ~debug =
309+
let path =
310+
match Filename.is_relative entryPointFile with
311+
| true -> Unix.realpath entryPointFile
312+
| false -> entryPointFile
313+
in
311314
if debug then Printf.printf "extracting docs for %s\n" path;
312315
let result =
313316
match
@@ -362,9 +365,9 @@ let extractDocs ~path ~debug =
362365
items =
363366
structure.items
364367
|> List.filter_map (fun (item : Module.item) ->
368+
let source = getSource ~rootPath item.loc in
365369
match item.kind with
366370
| Value typ ->
367-
let source = getSource ~rootPath item.loc in
368371
Some
369372
(Value
370373
{
@@ -376,8 +379,6 @@ let extractDocs ~path ~debug =
376379
name = item.name;
377380
deprecated = item.deprecated;
378381
source;
379-
(* source = *)
380-
(* getSource ~stamp:typ.id ~full ~name:item.name; *)
381382
})
382383
| Type (typ, _) ->
383384
Some
@@ -390,7 +391,7 @@ let extractDocs ~path ~debug =
390391
name = item.name;
391392
deprecated = item.deprecated;
392393
detail = typeDetail typ ~full ~env;
393-
source = getSource ~rootPath item.loc;
394+
source;
394395
})
395396
| Module (Ident p) ->
396397
(* module Whatever = OtherModule *)
@@ -416,7 +417,7 @@ let extractDocs ~path ~debug =
416417
{
417418
id;
418419
name = item.name;
419-
source = getSource ~rootPath item.loc;
420+
source;
420421
items;
421422
docstring =
422423
item.docstring @ internalDocstrings
@@ -433,7 +434,7 @@ let extractDocs ~path ~debug =
433434
name = m.name;
434435
docstring = item.docstring @ m.docstring;
435436
deprecated = item.deprecated;
436-
source = getSource ~rootPath item.loc;
437+
source;
437438
items = docs.items;
438439
})
439440
| Module

0 commit comments

Comments
 (0)