Skip to content

tools: add source field (Loc) #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tools: refactor
  • Loading branch information
aspeddro committed Jan 27, 2024
commit 79e7e1e9853e574c8a13ce2a6dffcf03d0d1245a
2 changes: 1 addition & 1 deletion tools/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let main () =
| Some "true" -> Analysis.Cfg.isDocGenFromCompiler := true
| _ -> ()
in
logAndExit (Tools.extractDocs ~path ~debug:false)
logAndExit (Tools.extractDocs ~entryPointFile:path ~debug:false)
| _ -> logAndExit (Error docHelp))
| "reanalyze" :: _ ->
let len = Array.length Sys.argv in
Expand Down
19 changes: 10 additions & 9 deletions tools/src/tools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,15 @@ let findRelativePath ~rootPath ~path =

let getSource ~rootPath ({loc_start} : Location.t) =
let line, col = Pos.ofLexing loc_start in

let filepath = findRelativePath ~rootPath ~path:loc_start.pos_fname in

{filepath; line = line + 1; col = col + 1}

let extractDocs ~path ~debug =
let extractDocs ~entryPointFile ~debug =
let path =
match Filename.is_relative entryPointFile with
| true -> Unix.realpath entryPointFile
| false -> entryPointFile
in
if debug then Printf.printf "extracting docs for %s\n" path;
let result =
match
Expand Down Expand Up @@ -362,9 +365,9 @@ let extractDocs ~path ~debug =
items =
structure.items
|> List.filter_map (fun (item : Module.item) ->
let source = getSource ~rootPath item.loc in
match item.kind with
| Value typ ->
let source = getSource ~rootPath item.loc in
Some
(Value
{
Expand All @@ -376,8 +379,6 @@ let extractDocs ~path ~debug =
name = item.name;
deprecated = item.deprecated;
source;
(* source = *)
(* getSource ~stamp:typ.id ~full ~name:item.name; *)
})
| Type (typ, _) ->
Some
Expand All @@ -390,7 +391,7 @@ let extractDocs ~path ~debug =
name = item.name;
deprecated = item.deprecated;
detail = typeDetail typ ~full ~env;
source = getSource ~rootPath item.loc;
source;
})
| Module (Ident p) ->
(* module Whatever = OtherModule *)
Expand All @@ -416,7 +417,7 @@ let extractDocs ~path ~debug =
{
id;
name = item.name;
source = getSource ~rootPath item.loc;
source;
items;
docstring =
item.docstring @ internalDocstrings
Expand All @@ -433,7 +434,7 @@ let extractDocs ~path ~debug =
name = m.name;
docstring = item.docstring @ m.docstring;
deprecated = item.deprecated;
source = getSource ~rootPath item.loc;
source;
items = docs.items;
})
| Module
Expand Down