[clang-tools-extra] r332959 - [clangd] Correctly handle IWYU prama with verbatim #include header.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Tue May 22 01:33:30 PDT 2018


Author: ioeric
Date: Tue May 22 01:33:30 2018
New Revision: 332959

URL: http://llvm.org/viewvc/llvm-project?rev=332959&view=rev
Log:
[clangd] Correctly handle IWYU prama with verbatim #include header.

Modified:
    clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp
    clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=332959&r1=332958&r2=332959&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Tue May 22 01:33:30 2018
@@ -65,8 +65,9 @@ collectIWYUHeaderMaps(CanonicalIncludes
       // FIXME(ioeric): resolve the header and store actual file path. For now,
       // we simply assume the written header is suitable to be #included.
       Includes->addMapping(PP.getSourceManager().getFilename(Range.getBegin()),
-                           Text.startswith("<") ? Text.str()
-                                                : ("\"" + Text + "\"").str());
+                           (Text.startswith("<") || Text.startswith("\""))
+                               ? Text.str()
+                               : ("\"" + Text + "\"").str());
       return false;
     }
 

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=332959&r1=332958&r2=332959&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Tue May 22 01:33:30 2018
@@ -651,6 +651,21 @@ TEST_F(SymbolCollectorTest, IWYUPragma)
                                  IncludeHeader("\"the/good/header.h\""))));
 }
 
+TEST_F(SymbolCollectorTest, IWYUPragmaWithDoubleQuotes) {
+  CollectorOpts.CollectIncludePath = true;
+  CanonicalIncludes Includes;
+  PragmaHandler = collectIWYUHeaderMaps(&Includes);
+  CollectorOpts.Includes = &Includes;
+  const std::string Header = R"(
+    // IWYU pragma: private, include "the/good/header.h"
+    class Foo {};
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+                           AllOf(QName("Foo"), DeclURI(TestHeaderURI),
+                                 IncludeHeader("\"the/good/header.h\""))));
+}
+
 TEST_F(SymbolCollectorTest, AvoidUsingFwdDeclsAsCanonicalDecls) {
   CollectorOpts.CollectIncludePath = true;
   Annotations Header(R"(




More information about the cfe-commits mailing list