[PATCH] D64863: [clangd] Ignore diags from builtin files
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 06:21:27 PDT 2019
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
Herald added a project: clang.
This fixes a case where we show diagnostics on arbitrary lines, in an
internal codebase.
Open for ideas on unittesting this.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64863
Files:
clang-tools-extra/clangd/Diagnostics.cpp
Index: clang-tools-extra/clangd/Diagnostics.cpp
===================================================================
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -469,6 +469,11 @@
}
bool InsideMainFile = isInsideMainFile(Info);
+ SourceManager &SM = Info.getSourceManager();
+ if (!InsideMainFile && SM.isWrittenInBuiltinFile(Info.getLocation())) {
+ IgnoreDiagnostics::log(DiagLevel, Info);
+ return;
+ }
auto FillDiagBase = [&](DiagBase &D) {
D.Range = diagnosticRange(Info, *LangOpts);
@@ -476,8 +481,7 @@
Info.FormatDiagnostic(Message);
D.Message = Message.str();
D.InsideMainFile = InsideMainFile;
- D.File = Info.getSourceManager().getFilename(Info.getLocation());
- auto &SM = Info.getSourceManager();
+ D.File = SM.getFilename(Info.getLocation());
D.AbsFile = getCanonicalPath(
SM.getFileEntryForID(SM.getFileID(Info.getLocation())), SM);
D.Severity = DiagLevel;
@@ -500,10 +504,9 @@
if (FixIt.RemoveRange.getBegin().isMacroID() ||
FixIt.RemoveRange.getEnd().isMacroID())
return false;
- if (!isInsideMainFile(FixIt.RemoveRange.getBegin(),
- Info.getSourceManager()))
+ if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
return false;
- Edits.push_back(toTextEdit(FixIt, Info.getSourceManager(), *LangOpts));
+ Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
}
llvm::SmallString<64> Message;
@@ -511,8 +514,8 @@
if (SyntheticMessage && Info.getNumFixItHints() == 1) {
const auto &FixIt = Info.getFixItHint(0);
bool Invalid = false;
- llvm::StringRef Remove = Lexer::getSourceText(
- FixIt.RemoveRange, Info.getSourceManager(), *LangOpts, &Invalid);
+ llvm::StringRef Remove =
+ Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, &Invalid);
llvm::StringRef Insert = FixIt.CodeToInsert;
if (!Invalid) {
llvm::raw_svector_ostream M(Message);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64863.210305.patch
Type: text/x-patch
Size: 2042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190717/51ead186/attachment.bin>
More information about the cfe-commits
mailing list