Remove single asterisk in usage example completion#5
Merged
jdrupal-dev merged 2 commits intojdrupal-dev:mainfrom Apr 25, 2025
Merged
Remove single asterisk in usage example completion#5jdrupal-dev merged 2 commits intojdrupal-dev:mainfrom
jdrupal-dev merged 2 commits intojdrupal-dev:mainfrom
Conversation
Owner
|
Nice catch. I would like to use Regex though as it will be easier to extend the pattern if we find other edge cases in the future. You can use this function which I have tested locally: /// Helper function to extract usage example from the preceding comment.
fn extract_usage_example_from_comment(&self, comment_node: &Node) -> Option<String> {
if comment_node.kind() != "comment" {
return None;
}
let comment_text = self.get_node_text(comment_node);
let start_tag = "@code";
let end_tag = "@endcode";
if let (Some(start_index), Some(end_index)) =
(comment_text.find(start_tag), comment_text.find(end_tag))
{
if end_index > start_index {
let code_start = start_index + start_tag.len();
let example = comment_text[code_start..end_index].trim();
// Regex to replace "* " or "*" from the beginning of a line.
let re = Regex::new(r"^\s*\*\s?").unwrap();
let cleaned_example = example
.lines()
.map(|line| re.replace(line, "").to_string())
.collect::<Vec<String>>();
return Some(
cleaned_example[..cleaned_example.len() - 1]
.join("\n")
.trim()
.to_string(),
);
}
}
None
} |
Contributor
Author
|
Sounds good thanks, pushed the change and tested it locally. |
jdrupal-dev
approved these changes
Apr 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey,
noticed a small bug in the form- and render- snippet (sorry :D).
In the current main branch, when there are multiple examples like above, the "*" doesn't get stripped (between the form arrays).
So currently there's an asterisk between.
This MR should fix that so
render-detailsworks properly.Maybe you could double check. So far I haven't found a snippet that looked wrong.