Skip to content
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

tools: add source field (Loc) #900

Merged
merged 7 commits into from
Jan 27, 2024
Merged

Conversation

aspeddro
Copy link
Contributor

Emit location of type/value/module

{filepath: "src/A.resi", line: 2, col: 2}

In general, you can run the command from anywhere. The filepath property is relative to the package root.

@zth
Copy link
Collaborator

zth commented Jan 27, 2024

Missing ReScript bindings here, right? Should add them to the ReScript files.

@aspeddro
Copy link
Contributor Author

ReScript files updated!

Comment on lines 286 to 304
let findRelativePath ~rootPath ~path =
let open Filename in
let realPath =
match rootPath = "." with
| true -> Sys.getcwd ()
| false ->
if is_relative rootPath then concat (Sys.getcwd ()) rootPath else rootPath
in
let rec loop dirPath acc =
match dirname dirPath = realPath with
| true -> basename dirPath :: acc |> String.concat "/"
| false -> (
match dirPath with
| "/" -> failwith "Failed to find relative path of package"
| "." -> path
| _ -> loop (dirname dirPath) (basename dirPath :: acc))
in

loop path []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No built in fn that does this I take it...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. Found in Analysis.Files.realpath

5396f79

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Now we just need to figure out the tests for Windows. Paths being different is obviously expected.

@zth zth merged commit 91714d8 into rescript-lang:master Jan 27, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants