-
Notifications
You must be signed in to change notification settings - Fork 19
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
Configurable Comment Filter to Support Multiple Programming Language Comment Formats #309
Conversation
We use markdown so it doesn't look like anything affects us. Would it make it cleaner though to put language (html|markdown) formatter options under their own keys for clarity? |
@bryannaegele Yes, for languages that natively support Markdown, this might be less relevant. However, |
Thanks a lot for putting it up, looks great, I just have a couple of minor comments:
do we have some specific case where it's necessary? Also, would it be based on ``` ? My usual reactions is to not add things until they are necessary (not a strong position).
would it escape special characters? (there is a need for it - dns query is a good test case) |
Yes, it’s based on ```. While we don’t have an immediate use case, identifying it now allows us to use precise terminology and avoid naming issues should the need arise in the future. Additionally, its implementation requires just a few lines of code, so I’m inclined to include it this time. However, I agree that, in general, we should avoid implementing features without a clear requirement.
Thanks, I’ll create a test case using your example to ensure that special characters are properly handled. |
The only question I have - specific to java doc needs, is if we can merge "brief" and "note" into the comment. Example jinja template:
Or, what Java actually wants to do:
|
Yes, and without the
For the Jinja expression above, the following semconv attribute...
...generates the following Javadoc
Not quite sure to understand this part of the comment. Are you talking about |
If the note includes a markdown block using triple backticks like:
Then for the rust 🦀 this needs to have
Not sure how this could be achieved with this comment filter. |
I was thinking of the description of a Metric where we may need to pull notes from attributes. I think what you have now solves all the issues in Java's codegen today |
The current implementation supports language specifications for code blocks. If the semconv definition includes the Node::Code(code) => match &code.lang {
Some(lang) => {
ctx.markdown
.push_str(&format!("```{}\n{}\n```\n", lang, code.value));
}
None => {
ctx.markdown
.push_str(&format!("```\n{}\n```\n", code.value));
}
} |
One possible approach for the metrics is to explore the feasibility of using a macro that returns the part of the comment derived from the attribute notes, or undefined when there is nothing to comment. This way, we could use the following statement to create the comment for the corresponding metric.
Similarly, we could introduce a Jinja function that returns formatted text or undefined if the parameter doesn’t exist., e.g. |
I don't think it's an enhancement, it's essential to create correct rust. |
Since this filter already supports the possibility of having a code block with the ‘ignore’ directive, I would say that allowing it to be added by default when it is not specified falls under the category of an enhancement :-). In any case, I will probably add this option before merging this PR. |
@jerbly I added the Markdown option |
@jsuereth, for complex comments composed of multiple sections that should only be generated when certain fields are defined, we could introduce the function
In this statement, if |
This PR introduces a new, optional
comment_formats
section in theweaver.yaml
file to specify the behavior of thecomment
filter. The primary objective is to create a highly configurablecomment
filter while maintaining simplicity in template usage.With this configuration in place, the Java code generation could define the following setup (example):
If the
note
equals the following markdown (the whitespaces at the beginning and the multiple dots at the end are included just to demonstrate the effect of thetrim
andremove_trailing_dots
flags):Then creating a javadoc comment for the note is as simple as this:
The generated output is:
The
comment
filter currently supports the following optional parameters:format
: A valid ID from thecomment_formats
configuration map.header
: A custom header for the comment block.prefix
: A custom prefix for each comment line.footer
: A custom footer for the comment block.indent
: Number of spaces to add before each comment line for indentation purposes.The
comment
filter processes input data as follows:{{ attr.note | comment(indent="2") }}
will not fail and will not produce any output ifattr.note
doesn't exist in the context.This configuration approach is designed to be extendable, allowing us to support more languages or nuances in code documentation. Therefore, I would appreciate your feedback before finalizing this PR to ensure all critical features are covered. If you notice any missing configuration options for your language, please leave a comment in this PR thread specifying the render or transform options you’d like to see included (@jsuereth , @lmolkova , @joaopgrassi , @trisch-me , @MadVikingGod , @bryannaegele ).
Task list:
comment_formats
config optionsdefault_comment_format
weaver.yaml
fileCloses #291