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
Introduce Canonicalize #99
Conversation
where Directory is the Vector of component paths. The refactor meant changing some sections of the code where we were parsing and manipulating Files/Directories. This also includes a new trait Canonicalization which is needed for import logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good !
I do have one big question : why is the file/directory distinction useful ? Since empty paths are allowed, we may have paths without a file, so what's the benefit of keeping the last component separatedly ?
dhall_syntax/src/core/import.rs
Outdated
authority: url.authority.clone(), | ||
path: url.path.canonicalize(), | ||
query: url.query.clone(), | ||
headers: url.headers.clone().map(|boxed_hash| Box::new(boxed_hash.canonicalize())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you could use as_ref
instead of clone
here, since canonicalize
only needs a reference.
_ => unimplemented!("{:?}", import), | ||
}; | ||
Ok(load_import(&path, import_cache, import_stack).map_err(|e| { | ||
Ok(load_import(&path_buf, import_cache, import_stack).map_err(|e| { | ||
ImportError::Recursive(import.clone(), Box::new(e)) | ||
})?) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this feature isn't tested by the tests from dhall-lang
, could you add some tests here ? You don't need to test every case, but a few basic ones would ensure it works and we don't accidentally break it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I just need to add the tests, and we're good to go here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to check I'm on the right page. I have a skeleton test where ?
is place holder for values:
#[test]
test_resolve_import_local() {
let import = Import {
mode: RawText,
location: Local(?FilePrefix, FilePath { file_path: ?file_path }),
hash: None,
};
let root = LocalDir(?cwd);
let import_cache = HashMap::new();
let import_stack = vec![];
let import_result = resolve_import(import, root, import_cache, import_stack);
assert_eq!(import_result, Ok(?some_result));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I'm so sorry I missed this comment >< I was thinking more simply to just test canonicalize
. For example
#[test]
test_canonicalize_whatever() {
let filepath = FilePath {filepath = vec!["foo", "..", "bar"]};
let expected = FilePath {filepath = vec!["bar"]};
assert_eq!(filepath.canonicalize(), expected);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sorry, that really wasn't clear from the diff this comment is pointing to
@FintanH Need a hand with the code or with reading the semantics ? |
@Nadrieril: thanks for checking in ❤️ Sorry I've left this so long, got snapped up with switching jobs and what not. I have some time off now and fully on the Rust train 🚂 I'll look at this during the week and possibly a bit at MuniHac 😁 |
Rename File to FilePath and have more consistent naming.
@Nadrieril I have a weird one:
I did a |
Ah yeah it seems there was a conflict between the version of proc_macro2 used by pest and the one used by quote. This should be fixed on master now |
Actually we may be able to test canonicalization with normal tests using |
Thanks! Sorry for my lack of work on it towards the end 😅 been very busy! |
Fixes #76
Refactor of File to be the combination of Directory and the file name,where Directory is the Vector of component paths.
The refactor meant changing some sections of the code where we were
parsing and manipulating Files/Directories.
This also includes a new trait Canonicalization which is needed for
import logic.
This is just the introduction of the trait, but calling it needs to be added as well. From what I could see that's involved with import chaining, is that right? Do we have that yet?