ilya-biryukov updated this revision to Diff 132430. ilya-biryukov added a comment.
- Show location of dropped diagnostic. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D42803 Files: clangd/ClangdUnit.cpp Index: clangd/ClangdUnit.cpp =================================================================== --- clangd/ClangdUnit.cpp +++ clangd/ClangdUnit.cpp @@ -27,6 +27,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> #include <chrono> @@ -178,15 +179,30 @@ llvm::Optional<DiagWithFixIts> toClangdDiag(const clang::Diagnostic &D, DiagnosticsEngine::Level Level, const LangOptions &LangOpts) { + SmallString<64> Message; + D.FormatDiagnostic(Message); + if (!D.hasSourceManager() || !D.getLocation().isValid() || - !D.getSourceManager().isInMainFile(D.getLocation())) + !D.getSourceManager().isInMainFile(D.getLocation())) { + + SmallString<64> Location; + if (D.hasSourceManager() && D.getLocation().isValid()) { + auto &SourceMgr = D.getSourceManager(); + auto Loc = SourceMgr.getFileLoc(D.getLocation()); + llvm::raw_svector_ostream OS(Location); + Loc.print(OS, SourceMgr); + } else { + Location = "<no-loc>"; + } + + log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}", + Location, Message)); return llvm::None; + } DiagWithFixIts Result; Result.Diag.range = diagnosticRange(D, LangOpts); Result.Diag.severity = getSeverity(Level); - SmallString<64> Message; - D.FormatDiagnostic(Message); Result.Diag.message = Message.str(); for (const FixItHint &Fix : D.getFixItHints()) Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));
Index: clangd/ClangdUnit.cpp =================================================================== --- clangd/ClangdUnit.cpp +++ clangd/ClangdUnit.cpp @@ -27,6 +27,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> #include <chrono> @@ -178,15 +179,30 @@ llvm::Optional<DiagWithFixIts> toClangdDiag(const clang::Diagnostic &D, DiagnosticsEngine::Level Level, const LangOptions &LangOpts) { + SmallString<64> Message; + D.FormatDiagnostic(Message); + if (!D.hasSourceManager() || !D.getLocation().isValid() || - !D.getSourceManager().isInMainFile(D.getLocation())) + !D.getSourceManager().isInMainFile(D.getLocation())) { + + SmallString<64> Location; + if (D.hasSourceManager() && D.getLocation().isValid()) { + auto &SourceMgr = D.getSourceManager(); + auto Loc = SourceMgr.getFileLoc(D.getLocation()); + llvm::raw_svector_ostream OS(Location); + Loc.print(OS, SourceMgr); + } else { + Location = "<no-loc>"; + } + + log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}", + Location, Message)); return llvm::None; + } DiagWithFixIts Result; Result.Diag.range = diagnosticRange(D, LangOpts); Result.Diag.severity = getSeverity(Level); - SmallString<64> Message; - D.FormatDiagnostic(Message); Result.Diag.message = Message.str(); for (const FixItHint &Fix : D.getFixItHints()) Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits