aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2020-08-13 14:27:15 +0200
committerSam McCall <sam.mccall@gmail.com>2020-08-13 14:27:32 +0200
commit41d0edd54e29e994fa7d40961a38e8fca27addac (patch)
treeeef92059dc89737579f9604cc1f3ee2890ce3f5e
parent44587e2f7e732604cd6340061d40ac21e7e188e5 (diff)
downloadllvm-41d0edd54e29e994fa7d40961a38e8fca27addac.zip
llvm-41d0edd54e29e994fa7d40961a38e8fca27addac.tar.gz
llvm-41d0edd54e29e994fa7d40961a38e8fca27addac.tar.bz2
[clangd] Express dumpAST in tests as a customAction()
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp20
-rw-r--r--clang-tools-extra/clangd/ClangdServer.h4
-rw-r--r--clang-tools-extra/clangd/ParsedAST.cpp4
-rw-r--r--clang-tools-extra/clangd/ParsedAST.h4
-rw-r--r--clang-tools-extra/clangd/unittests/ClangdTests.cpp22
-rw-r--r--clang-tools-extra/clangd/unittests/SyncAPI.cpp6
-rw-r--r--clang-tools-extra/clangd/unittests/SyncAPI.h2
7 files changed, 19 insertions, 43 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 919d59a..cd6cba8 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -525,26 +525,6 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
WorkScheduler.runWithAST("ApplyTweak", File, std::move(Action));
}
-void ClangdServer::dumpAST(PathRef File,
- llvm::unique_function<void(std::string)> Callback) {
- auto Action = [Callback = std::move(Callback)](
- llvm::Expected<InputsAndAST> InpAST) mutable {
- if (!InpAST) {
- llvm::consumeError(InpAST.takeError());
- return Callback("<no-ast>");
- }
- std::string Result;
-
- llvm::raw_string_ostream ResultOS(Result);
- clangd::dumpAST(InpAST->AST, ResultOS);
- ResultOS.flush();
-
- Callback(Result);
- };
-
- WorkScheduler.runWithAST("DumpAST", File, std::move(Action));
-}
-
void ClangdServer::locateSymbolAt(PathRef File, Position Pos,
Callback<std::vector<LocatedSymbol>> CB) {
auto Action = [Pos, CB = std::move(CB),
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 7aed7d4..1bc7d70 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -295,10 +295,6 @@ public:
void applyTweak(PathRef File, Range Sel, StringRef ID,
Callback<Tweak::Effect> CB);
- /// Only for testing purposes.
- /// Waits until all requests to worker thread are finished and dumps AST for
- /// \p File. \p File must be in the list of added documents.
- void dumpAST(PathRef File, llvm::unique_function<void(std::string)> Callback);
/// Called when an event occurs for a watched file in the workspace.
void onFileEvent(const DidChangeWatchedFilesParams &Params);
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index 7a7853a..35e7fd7 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -238,10 +238,6 @@ private:
} // namespace
-void dumpAST(ParsedAST &AST, llvm::raw_ostream &OS) {
- AST.getASTContext().getTranslationUnitDecl()->dump(OS, true);
-}
-
llvm::Optional<ParsedAST>
ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
std::unique_ptr<clang::CompilerInvocation> CI,
diff --git a/clang-tools-extra/clangd/ParsedAST.h b/clang-tools-extra/clangd/ParsedAST.h
index 361b20a..05818b9 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -146,10 +146,6 @@ private:
CanonicalIncludes CanonIncludes;
};
-/// For testing/debugging purposes. Note that this method deserializes all
-/// unserialized Decls, so use with care.
-void dumpAST(ParsedAST &AST, llvm::raw_ostream &OS);
-
} // namespace clangd
} // namespace clang
diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index 585fabe6..a7c2568 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -139,9 +139,25 @@ std::string replacePtrsInDump(std::string const &Dump) {
return Result;
}
+std::string dumpAST(ClangdServer &Server, PathRef File) {
+ std::string Result;
+ Notification Done;
+ Server.customAction(File, "DumpAST", [&](llvm::Expected<InputsAndAST> AST) {
+ if (AST) {
+ llvm::raw_string_ostream ResultOS(Result);
+ AST->AST.getASTContext().getTranslationUnitDecl()->dump(ResultOS, true);
+ } else {
+ llvm::consumeError(AST.takeError());
+ Result = "<no-ast>";
+ }
+ Done.notify();
+ });
+ Done.wait();
+ return Result;
+}
+
std::string dumpASTWithoutMemoryLocs(ClangdServer &Server, PathRef File) {
- auto DumpWithMemLocs = runDumpAST(Server, File);
- return replacePtrsInDump(DumpWithMemLocs);
+ return replacePtrsInDump(dumpAST(Server, File));
}
class ClangdVFSTest : public ::testing::Test {
@@ -607,7 +623,7 @@ TEST_F(ClangdVFSTest, InvalidCompileCommand) {
// Clang can't parse command args in that case, but we shouldn't crash.
runAddDocument(Server, FooCpp, "int main() {}");
- EXPECT_EQ(runDumpAST(Server, FooCpp), "<no-ast>");
+ EXPECT_EQ(dumpAST(Server, FooCpp), "<no-ast>");
EXPECT_ERROR(runLocateSymbolAt(Server, FooCpp, Position()));
EXPECT_ERROR(runFindDocumentHighlights(Server, FooCpp, Position()));
EXPECT_ERROR(runRename(Server, FooCpp, Position(), "new_name",
diff --git a/clang-tools-extra/clangd/unittests/SyncAPI.cpp b/clang-tools-extra/clangd/unittests/SyncAPI.cpp
index c356fb0..fb810f4 100644
--- a/clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ b/clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -112,12 +112,6 @@ runFormatFile(ClangdServer &Server, PathRef File, StringRef Code) {
return std::move(*Result);
}
-std::string runDumpAST(ClangdServer &Server, PathRef File) {
- llvm::Optional<std::string> Result;
- Server.dumpAST(File, capture(Result));
- return std::move(*Result);
-}
-
SymbolSlab runFuzzyFind(const SymbolIndex &Index, llvm::StringRef Query) {
FuzzyFindRequest Req;
Req.Query = std::string(Query);
diff --git a/clang-tools-extra/clangd/unittests/SyncAPI.h b/clang-tools-extra/clangd/unittests/SyncAPI.h
index 63a128d..944717d 100644
--- a/clang-tools-extra/clangd/unittests/SyncAPI.h
+++ b/clang-tools-extra/clangd/unittests/SyncAPI.h
@@ -47,8 +47,6 @@ llvm::Expected<FileEdits> runRename(ClangdServer &Server, PathRef File,
llvm::Expected<tooling::Replacements>
runFormatFile(ClangdServer &Server, PathRef File, StringRef Code);
-std::string runDumpAST(ClangdServer &Server, PathRef File);
-
SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query);
SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req);
RefSlab getRefs(const SymbolIndex &Index, SymbolID ID);