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

Add source information as path of the information #2466

Merged
merged 16 commits into from
Dec 11, 2024
Merged

Conversation

psibi
Copy link
Contributor

@psibi psibi commented Nov 16, 2024

Motivation: To add support for module integration in justl which is an Emacs extension for driving justfiles within Emacs.

This would allow me to easily discover the file locations of different just modules and allow the ability to individually open justl buffers for them within the editor.

More info here:

@casey
Copy link
Owner

casey commented Nov 17, 2024

Seems reasonable to me! Would it be better to have relative paths or absolute paths?

@psibi
Copy link
Contributor Author

psibi commented Nov 17, 2024

Would it be better to have relative paths or absolute paths?

Yeah, I think absolute paths would be more convenient. And it was trivial to implement it. Let me see how to make the tests pass using that.

Motivation: To add support for module integration in justl which is an
Emacs extension for driving justfiles within Emacs.

This would allow me to easily discover the file locations of different
just modules and allow the ability to individually open justl buffers
for them within the editor.
@psibi
Copy link
Contributor Author

psibi commented Nov 18, 2024

@casey This is ready for review now.

Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

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

See comments!

src/analyzer.rs Outdated
@@ -182,6 +182,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
unstable_features.insert(UnstableFeature::ScriptInterpreterSetting);
}

let source = root.canonicalize().unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

Canonicalize produces weird paths. On Unix, it resolves symlinks, which is often not what you want, and on Windows it produces paths prefixed with \\?\ which is not very nice.

Canonicalize is also a system call, which means it can fail with an I/O error, so we can't unwrap here.

If we need to clean the path, we should use .lexiclean() instead of canonicalize, which cannot fail and doesn't produce weird paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed a fix, but the tests in MacOS fails because I think of symbolic link. Do you know how to handle 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.

Okay, I have pushed a fix where I have to use canonicalize only for the tests to make it pass. Let me know what you think.

tests/json.rs Outdated
@@ -1,22 +1,37 @@
use super::*;

fn case(justfile: &str, value: Value) {
fn case<F: Fn(&Path) -> Value>(justfile: &str, value: F) {
Copy link
Owner

Choose a reason for hiding this comment

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

The JSON tests are pretty horrible. I changed the case function so that you pass in a struct which should serialize to the output of --dump.

You can take advantage of this by putting the relative path in the source field of the passed in Module, and then, in case, prepending the path to the temporary directory, which will make them match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. :-)

@casey casey enabled auto-merge (squash) December 11, 2024 00:30
@casey casey merged commit 5393105 into casey:master Dec 11, 2024
5 checks passed
Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

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

LGTM. source is now absolute, instead of relative, and it's used in some other places which were expecting a relative path. I fixed those up and I think they're okay.

@psibi
Copy link
Contributor Author

psibi commented Dec 11, 2024

Thank you!

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