-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat(doc): append after function description the link for the tests #555
Conversation
The latest change generate this markdown:
Returns index of the first value found in the specified array. If the value is not found, the function returns -1.
|
src/modules/function/declaration.rs
Outdated
let mut test_reference = String::from("You can check the original tests for code examples: "); | ||
let mut found_test = false; | ||
if exe_path.contains("target/debug") { | ||
let file_std = meta.context.path.as_ref().and_then(|p| Path::new(&p).file_name()?.to_str().map(|s| s.to_string())).unwrap_or_default(); |
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 got that with chatgpt I wasn't able to find a way from Some("./src/std/array.ab")
to get only array.ab
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.
okay im not exactly sure what exactly is wrong but there is something wrong with this line.. i will take a closer look tomorrow
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 probably my code can written better :-P
src/modules/function/declaration.rs
Outdated
result.push("```ab".to_string()); | ||
result.push(self.doc_signature.to_owned().unwrap()); | ||
result.push("```\n".to_string()); | ||
if let Some(comment) = &self.comment { | ||
result.push(comment.document(meta)); | ||
} | ||
|
||
if found_test { | ||
test_reference.truncate(test_reference.len() - 2); |
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.
this to remove the last ,
so I can add a dot to end the sentence.
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.
what about .trim_end_matches(" ,")
so it will remove only when it is exactly the ,
at the end
also if you're joining an array of strings theres a Vec<String>.join()
for that
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 its ok
@hdwalters you can commit those changes yourself in github web editor |
Apparently I was able to push to the branch on @Mte90's fork from the command line. |
result.push(format!("## `{}`", self.name)); | ||
result.push(format!("## `{}`\n", self.name)); | ||
|
||
let references = self.create_reference(meta, &mut 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.
I moved the new code to a helper function, which returns an optional string vector (encapsulating both the success of the function, and the additional lines to be added at end of section).
result.join("\n") | ||
} | ||
} | ||
|
||
impl FunctionDeclaration { | ||
#[cfg(debug_assertions)] |
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.
This annotation ensures the new code is only compiled for debug builds, so we don't need to test whether the path contains target/debug
. The function annotated with the complementary #[cfg(not(debug_assertions))]
below hard codes the return value to None
for release builds.
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.
how we can compile a debug build? cargo build
locally is enough? just to check the CI if needs something to not compile that
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.
Use cargo build
for a debug build, cargo build --release
for a release build.
let mut references = Vec::new(); | ||
let exe_path = env::current_exe() | ||
.expect("Executable path not found"); | ||
let root_path = exe_path.parent() |
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.
All path operations are now done via Path
and PathBuf
objects, for reliability and cross-platform support; no hard-coded /
path separators any more.
src/modules/function/declaration.rs
Outdated
result.push(String::from("```\n")); | ||
if test_path.exists() && test_path.is_dir() { | ||
if let Ok(entries) = fs::read_dir(test_path) { | ||
let pattern = glob::Pattern::new(&format!("{}*.ab", self.name)).unwrap(); |
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.
Glob pattern is only created once, rather than for each entry in the directory.
.and_then(OsStr::to_str) | ||
.map(String::from) | ||
.unwrap_or_default(); | ||
result.push(String::from("```ab")); |
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.
Triple backticks are put on their own lines, and include an ab
annotation, so the output is consistent with other code blocks.
let path = entry.path(); | ||
if let Some(file_name) = path.file_name().and_then(OsStr::to_str) { | ||
if pattern.matches(file_name) { | ||
references.push(format!("* [{}](https://github.com/amber-lang/amber/blob/master/src/tests/stdlib/{})", file_name, file_name)); |
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.
Each test file is put on its own line, in a markdown bullet list.
So basically Amber compiled in:
This is a bit stinky but it's good enough for now. We should design a
|
This is a backporting of amber-lang/amber#555
Ref: #500
The markdown generated:
The code basically check if we are using the amber dev version, in this way can get the tests and generate the list.
My rust code will be horrible for sure.