[clangd] Check for include overlapping looks for only the line now.
authorKadir Cetinkaya <kadircet@google.com>
Thu, 23 Aug 2018 15:55:27 +0000 (15:55 +0000)
committerKadir Cetinkaya <kadircet@google.com>
Thu, 23 Aug 2018 15:55:27 +0000 (15:55 +0000)
Summary:
Currently we match an include only if we are inside filename, with this patch we
will match whenever we are on the starting line of the include.

Reviewers: ilya-biryukov, hokein, ioeric

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51163

llvm-svn: 340539

clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/unittests/clangd/XRefsTests.cpp

index a79a8d1..97fee3a 100644 (file)
@@ -211,7 +211,7 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos,
   std::vector<Location> Result;
   // Handle goto definition for #include.
   for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
-    if (!Inc.Resolved.empty() && Inc.R.contains(Pos))
+    if (!Inc.Resolved.empty() && Inc.R.start.line == Pos.line)
       Result.push_back(Location{URIForFile{Inc.Resolved}, {}});
   }
   if (!Result.empty())
index 2558cde..47af725 100644 (file)
@@ -1014,11 +1014,13 @@ TEST(GoToInclude, All) {
 
   Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("5"));
   ASSERT_TRUE(bool(Locations)) << "findDefinitions returned an error";
-  EXPECT_THAT(*Locations, IsEmpty());
+  EXPECT_THAT(*Locations,
+              ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
 
   Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("7"));
   ASSERT_TRUE(bool(Locations)) << "findDefinitions returned an error";
-  EXPECT_THAT(*Locations, IsEmpty());
+  EXPECT_THAT(*Locations,
+              ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
 }
 
 TEST(GoToDefinition, WithPreamble) {