Skip to content

Commit

Permalink
Revert "[clangd] Implement textDocument/implementation (Xref layer)"
Browse files Browse the repository at this point in the history
This reverts commit 4324320.
  • Loading branch information
usx95 committed Nov 18, 2020
1 parent 480ad4a commit 0016ab6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 115 deletions.
46 changes: 0 additions & 46 deletions clang-tools-extra/clangd/XRefs.cpp
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions clang-tools-extra/clangd/XRefs.h
Expand Up @@ -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,
Expand Down
66 changes: 2 additions & 64 deletions clang-tools-extra/clangd/unittests/XRefsTests.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0016ab6

Please sign in to comment.