-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use @snippet javadoc tag for snippets #14257
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
Comments
google/google-java-format#789 Unfortunately, I think these make this issue a no-go to unless you want to resign from using google java formatter... which I don't think we should do. |
Related: if we bump main to java 23+ (#14229) then we could do snippets in javadoc with the typical markdown mechanisms. |
The markdown would have a huge advantage for the many analyzers with xml-style prettyprint docs today. I don't think For me, editor displays the current "prettyprint" of analyzers XML docs without any syntax highlighting: On the other hand, with markdown you'd get this: <fieldType name="text_arnormal" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.ArabicNormalizationFilterFactory"/>
</analyzer>
</fieldType> |
@dweiss what do you think about exploring the option to swap out spotless I know the history that google says nobody else's formatter is good enough, they say you need "their" formatter for the google style and that others eclipse/intellij can't do it right, but their formatter can't support |
The Palantir one is no better off from what I can tell, it is a fork of the google one with some cosmetic tweaks. I know eclipse JDT doesn't choke on these constructs, although I don't have much experience with their formatter, their compiler has been pretty good and they are generally responsive about new java features. |
I have been using google's tool mostly because it's been fairly solid in terms of formatting between releases (so no surprise changes on updates). I also like (or have slowly grown accustomed to) what they do with the indents and more complex code blocks. There are quirks, sure, but they'll be present with any tool. The beauty of having a single standard should be that the tool used to format the code is irrelevant as long, as it ends up with the same output. If we can make eclipse do the same thing (or even better, format snippets reliably) then it's a transparent change for the better - I don't have a problem with that at all. |
It's close but there are many differences. See the commit above and try running it on one of the modules, for example suggest (./gradlew -p lucene/suggest spotlessApply). Maybe it can be made closer, I haven't tried. |
@dweiss thank you so much for that starter commit for evaluation. I will try it tonight and fire up eclipse and see what our options are. I finally finished parser (https://github.com/rmuir/tree-sitter-javadoc) and am now looking at options to (ab)use it, to convert our docs to markdown automatically, when I discovered that google-java-format will mess up markdown comments, e.g. too-long So currently, there is no way to escape from the prettier because neither |
I think in the markdown case, the bug I saw was that it didn't treat |
google/google-java-format#1193
So it seems it's broken entirely. Argh. |
I played with this a bit and reduced noise in two ways: Original file: 113 files changed, 3656 insertions(+), 5216 deletions(-)
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/> 93 files changed, 2525 insertions(+), 3861 deletions(-)
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false"/> 75 files changed, 1922 insertions(+), 3380 deletions(-) Eclipse has a lot of options and I think this file is just out of date. With the unnecessary noise out of the way, it is a matter of exploring all the settings and trying to reduce the differences more. I'm guessing there would always be differences, but it would be nice to minimize them. |
For the record those diffstats were based on |
@dweiss I also wonder, with an "autoformat" workflow, if we even care so much. I don't understand what is so sacrosanct about google's format: to me it is ugly. Snippet tag is from java 18 (6 releases back) and google doesn't care, they are a big corporation and probably the type to keep code on e.g. java 8. I don't think we should weigh their opinions very much on anything. All autoformatters lead to ugliness at times, it is just the tradeoff you make to avoid hassles, and still reap the benefits of avoiding formatting bikesheds, noise in PRs, etc. I just think autoformat the code in a consistent way, call it a day. |
I agree, it does not matter which one you pick if it's an automated process.
My initial choice of gjf was motivated purely on subjective experience - I just liked the way it formatted code, that's it (I still do). Perhaps one more contributing factor was that I didn't want to play with a gazillion of Eclipse's options... this also facilitates the discussions concerning "which settings are best"... it's what it is, end of discussion. :) But I don't take it personally, really. I myself filed one or two issues with them and there is definitely corporate inertia in changing things. So if switching to Eclipse lets us make advancements (like with markdown javadocs), let's just do it. I'm fine with it. |
We'd probably have to apply reformatting to 10x and main to keep cherry picking easier. Other than that - it's a simple thing to do. |
I will play with the "don't reformat javadoc option". Maybe it's an easier solution to these problems? If we can coerce Google formatter to treat |
I've toyed with it a bit but I don't see a way for it to not break those /// comments. An alternative is to fork it, fix what we need and then use the forked version from spotless. This is a doable alternative to using Eclipse's formatter - I really don't mind either. |
All it takes would be to preserve any formatting in markdown comments (the /// lines) - a dumb check above would do the trick, I think. |
@dweiss I'm wondering if we could send them a PR such that any |
Yeah. I'll take a look at that, interesting. Part of the problem is that different Java versions seem to be returning a different tokenization of those comment strings. Seems like something has changed even from this issue that I filed. google/google-java-format#1153 because when I run it now on this input:
it breaks the first long line incorrectly:
I'll take a look in the evening. I don't think it should touch those /// lines at all. |
@dweiss I think that is because google-java-format uses internal JDK compiler apis to parse it. just like error prone. it is why you have to add all the opens? |
Yes, that's correct - google/google-java-format#1153 (comment) |
Here is what I did.
It seems to work (I've modified one of the classes, intentionally leaving a super-long line there). This is just a PoC that it's doable... I'm not sure if this patch would be accepted to google-java-format as is (it makes an assumption that anything starting with /// should just be left alone). I also don't think we can store a binary blob of google java format in Lucene repository. I can try to initiate a discussion with google-java-format folks first. If this doesn't work, I can publish my fork under my own coordinates to Maven Central - then we won't need the local binary blob and things should just work. [1] google/google-java-format@master...dweiss:google-java-format:preserve-markdown-like-lines |
@dweiss very nice. the Its this case: /// long comment...
public class foo {
/// another long comment...
public void bar(){}
} |
It'll work with those indented lines as well - it actually will align block indentation to the column they should be starting at. So:
ends up this after running tidy:
|
awesome! I really hope the patch is accepted: this will definitely give us a path forward. |
Let's wait a few days and see if there's any feedback. Like I mentioned above, what we use for formatting/checking format adherence shouldn't really matter for anybody who uses gradlew tidy in Lucene - gcf is an ASL licensed software and if we find anything problematic, I'll just publish my own fork and we can switch to that (and then we have the freedom of doing whatever, including applying markdown formatting of our own... like https://github.com/commonmark/commonmark-java). |
yeah: only thing I will say about choice of formatter is that normally I try to configure the editor in the repo to match what the build expects. e.g. for languages like python and typescript, it means disabling all formatting-related diagnostics and enabling "format-on-save" and "organize-imports-on-save", so that things "just work". It makes for easy dev experience where users have less friction with CI. But with java, such a setup seems difficult to achieve: I'm not sure anyone even has that today. |
You're right - this may be a problem. I use intellij and even gjf there does not work exactly the same way (google/google-java-format#1165). I stopped caring after a while. Just do whatever I need, then run a tidy before committing. I know - not ideal. But at least a workable solution. |
Description
Now that main requires Java 21, we can start using the
@snippet
javadoc tag, which is quite more convenient to use than the<pre class="prettyprint"></pre>
HTML tags we are currently using.One problem I noticed is that
gradlew tidy
messes up with formatting when@snippet
tags are used.The text was updated successfully, but these errors were encountered: