[clang-tools-extra] 0016ab6 - Revert "[clangd] Implement textDocument/implementation (Xref layer)"
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 18 09:06:44 PST 2020
Author: Utkarsh Saxena
Date: 2020-11-18T18:05:16+01:00
New Revision: 0016ab6f3632968e52eb83de021908f0c94bbb10
URL: https://github.com/llvm/llvm-project/commit/0016ab6f3632968e52eb83de021908f0c94bbb10
DIFF: https://github.com/llvm/llvm-project/commit/0016ab6f3632968e52eb83de021908f0c94bbb10.diff
LOG: Revert "[clangd] Implement textDocument/implementation (Xref layer)"
This reverts commit 43243208fa6fafe8b91e42c82bc56db9d99f76d3.
Added:
Modified:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/XRefs.h
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 7a7a022b32ea..db61452e0f17 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1124,52 +1124,6 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
return Result;
}
-std::vector<LocatedSymbol> findImplementations(ParsedAST &AST, Position Pos,
- const SymbolIndex *Index) {
- // We rely on index to find the implementations in subclasses.
- // FIXME: Index can be stale, so we may loose some latest results from the
- // main file.
- if (!Index)
- return {};
- const SourceManager &SM = AST.getSourceManager();
- auto MainFilePath =
- getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
- if (!MainFilePath) {
- elog("Failed to get a path for the main file, so no implementations.");
- return {};
- }
- auto CurLoc = sourceLocationInMainFile(SM, Pos);
- if (!CurLoc) {
- elog("Failed to convert position to source location: {0}",
- CurLoc.takeError());
- return {};
- }
- std::vector<LocatedSymbol> Results;
- DeclRelationSet Relations =
- DeclRelation::TemplatePattern | DeclRelation::Alias;
- RelationsRequest Req;
- Req.Predicate = RelationKind::OverriddenBy;
- for (const NamedDecl *ND : getDeclAtPosition(AST, *CurLoc, Relations))
- if (const CXXMethodDecl *CXXMD = llvm::dyn_cast<CXXMethodDecl>(ND))
- if (CXXMD->isVirtual())
- Req.Subjects.insert(getSymbolID(ND));
-
- if (Req.Subjects.empty())
- return Results;
- Index->relations(Req, [&](const SymbolID &Subject, const Symbol &Object) {
- if (auto DeclLoc =
- indexToLSPLocation(Object.CanonicalDeclaration, *MainFilePath)) {
- LocatedSymbol Loc;
- Loc.Name = Object.Name.str();
- Loc.PreferredDeclaration = *DeclLoc;
- if (auto DefLoc = indexToLSPLocation(Object.Definition, *MainFilePath))
- Loc.Definition = *DefLoc;
- Results.push_back(Loc);
- }
- });
- return Results;
-}
-
ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
const SymbolIndex *Index) {
if (!Limit)
diff --git a/clang-tools-extra/clangd/XRefs.h b/clang-tools-extra/clangd/XRefs.h
index fac1a992a12f..521c28f934be 100644
--- a/clang-tools-extra/clangd/XRefs.h
+++ b/clang-tools-extra/clangd/XRefs.h
@@ -82,11 +82,6 @@ struct ReferencesResult {
std::vector<Location> References;
bool HasMore = false;
};
-
-/// Returns implementations of the virtual function at a specified \p Pos.
-std::vector<LocatedSymbol> findImplementations(ParsedAST &AST, Position Pos,
- const SymbolIndex *Index);
-
/// Returns references of the symbol at a specified \p Pos.
/// \p Limit limits the number of results returned (0 means no limit).
ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 31d2a37f64a7..efca92fd0e9f 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,7 +43,6 @@ using ::testing::IsEmpty;
using ::testing::Matcher;
using ::testing::UnorderedElementsAre;
using ::testing::UnorderedElementsAreArray;
-using ::testing::UnorderedPointwise;
MATCHER_P2(FileRange, File, Range, "") {
return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
@@ -1162,12 +1161,12 @@ TEST(LocateSymbol, Alias) {
)cpp",
};
- for (const auto *Case : Tests) {
+ for (const auto* Case : Tests) {
SCOPED_TRACE(Case);
auto T = Annotations(Case);
auto AST = TestTU::withCode(T.code()).build();
EXPECT_THAT(locateSymbolAt(AST, T.point()),
- UnorderedPointwise(DeclRange(), T.ranges()));
+ ::testing::UnorderedPointwise(DeclRange(), T.ranges()));
}
}
@@ -1465,67 +1464,6 @@ TEST(LocateSymbol, NearbyIdentifier) {
}
}
-TEST(FindImplementations, Inheritance) {
- llvm::StringRef Test = R"cpp(
- struct Base {
- virtual void F$1^oo();
- void C$4^oncrete();
- };
- struct Child1 : Base {
- void $1[[Fo$3^o]]() override;
- virtual void B$2^ar();
- void Concrete(); // No implementations for concrete methods.
- };
- struct Child2 : Child1 {
- void $3[[Foo]]() override;
- void $2[[Bar]]() override;
- };
- void FromReference() {
- Base* B;
- B->Fo$1^o();
- B->C$4^oncrete();
- &Base::Fo$1^o;
- Child1 * C1;
- C1->B$2^ar();
- C1->Fo$3^o();
- }
- )cpp";
-
- Annotations Code(Test);
- auto TU = TestTU::withCode(Code.code());
- auto AST = TU.build();
- for (const std::string &Label : {"1", "2", "3", "4"}) {
- for (const auto &Point : Code.points(Label)) {
- EXPECT_THAT(findImplementations(AST, Point, TU.index().get()),
- UnorderedPointwise(DeclRange(), Code.ranges(Label)))
- << Code.code() << " at " << Point << " for Label " << Label;
- }
- }
-}
-
-TEST(FindImplementations, CaptureDefintion) {
- llvm::StringRef Test = R"cpp(
- struct Base {
- virtual void F^oo();
- };
- struct Child1 : Base {
- void $Decl[[Foo]]() override;
- };
- struct Child2 : Base {
- void $Child2[[Foo]]() override;
- };
- void Child1::$Def[[Foo]]() { /* Definition */ }
- )cpp";
- Annotations Code(Test);
- auto TU = TestTU::withCode(Code.code());
- auto AST = TU.build();
- EXPECT_THAT(
- findImplementations(AST, Code.point(), TU.index().get()),
- UnorderedElementsAre(Sym("Foo", Code.range("Decl"), Code.range("Def")),
- Sym("Foo", Code.range("Child2"), llvm::None)))
- << Test;
-}
-
TEST(FindReferences, WithinAST) {
const char *Tests[] = {
R"cpp(// Local variable
More information about the cfe-commits
mailing list