kadircet created this revision. kadircet added reviewers: ilya-biryukov, hokein, ioeric. Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
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. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51163 Files: clangd/XRefs.cpp unittests/clangd/XRefsTests.cpp Index: unittests/clangd/XRefsTests.cpp =================================================================== --- unittests/clangd/XRefsTests.cpp +++ unittests/clangd/XRefsTests.cpp @@ -1014,11 +1014,13 @@ 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) { Index: clangd/XRefs.cpp =================================================================== --- clangd/XRefs.cpp +++ clangd/XRefs.cpp @@ -211,7 +211,7 @@ 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: unittests/clangd/XRefsTests.cpp =================================================================== --- unittests/clangd/XRefsTests.cpp +++ unittests/clangd/XRefsTests.cpp @@ -1014,11 +1014,13 @@ 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) { Index: clangd/XRefs.cpp =================================================================== --- clangd/XRefs.cpp +++ clangd/XRefs.cpp @@ -211,7 +211,7 @@ 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())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits