See details in https://llvm.org/bugs/show_bug.cgi?id=26132
Details
Diff Detail
Event Timeline
I'm not sure tooling::Replacement is the best place to store check name. Maybe create a separate wrapper class and serialize it instead (clang-apply-replacements will have to be changed to support this format as well). This could be ClangTidyDiagnostic or just Diagnostic, and we could also store the message and other useful information in it.
tools/clang/include/clang/Tooling/Core/Replacement.h | ||
---|---|---|
93 | Please clang-format the code. | |
tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp | ||
80–81 | Doesn't it compile without StringRef() around Error.CheckName? |
What kind of wrapper should it be?
I was thinking of this kind:
class ExtendedReplacement : public Replacement { public: ExtendedReplacement(StringRef CheckName, Replacement &R); StringRef getCheckName() const { return CheckName; } std::string CheckName; }
but in this case (Replacement.h:141)
typedef std::set<Replacement> Replacements;
should be changed to
typedef std::set<ExtendedReplacement> Replacements;
which means a lot of code will be changed.
Is that an acceptable change? Or you meant another kind of wrapper?
No, I meant a different thing: serialize ClangTidyError or make a specialized structure for this purpose. Apart from replacements it contains the diagnostic message, diagnostic location, and the check name. We'll just need to teach clang-apply-replacements to read this structure.
Now the class that is serialized is Diagnostics.
I've moved ClangTidyError and ClangTidyMessage to the upper level, and renamed to Diagnostics and DiagnosticsMessage. Now any tool can use this classes, they contain more information than than Replacement. I think Diagnostics is a good class to add some more information later.
Please, review the fix, if it's ok I'll run clang-format on the changed code and provide the documentation. Thanks!
Fixed YAML format (was not correct in the last patch).
Grouped replacements in YAML by Diagnostics. It will help to apply replacements for one fix at once.
YAML report looks like this now:
--- MainSourceFile: '' Diagnostics: CheckName: misc-macro-parentheses Replacements: - FilePath: /media/SSD_/code/zdoom/main_1.cpp Offset: 1354 Length: 0 ReplacementText: '(' - FilePath: /media/SSD_/code/zdoom/main_1.cpp Offset: 1355 Length: 0 ReplacementText: ')' Diagnostics: CheckName: misc-macro-parentheses Replacements: - FilePath: /media/SSD_/code/zdoom/main_1.cpp Offset: 1452 Length: 0 ReplacementText: '(' - FilePath: /media/SSD_/code/zdoom/main_1.cpp Offset: 1453 Length: 0 ReplacementText: ')' ...
Sorry for the loooong delay. I missed you patch among all other ones. Could you rebase your patch on top of HEAD and clang-format the files you changed? I'll come back with more substantial comments early next week.
The main concern here is that the clang-apply-replacements tool should be able to read this format. See the clang/tools/extra/clang-tidy/tool/run-clang-tidy.py script for an example of its usage.
alexfh,
OK. I'll take a look at apply-replacements and fix if needed, in the beginning of the next week!
Please clang-format the code.