[clang-tools-extra] 41d0edd - [clangd] Express dumpAST in tests as a customAction()
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 13 05:27:41 PDT 2020
Author: Sam McCall
Date: 2020-08-13T14:27:32+02:00
New Revision: 41d0edd54e29e994fa7d40961a38e8fca27addac
URL: https://github.com/llvm/llvm-project/commit/41d0edd54e29e994fa7d40961a38e8fca27addac
DIFF: https://github.com/llvm/llvm-project/commit/41d0edd54e29e994fa7d40961a38e8fca27addac.diff
LOG: [clangd] Express dumpAST in tests as a customAction()
Added:
Modified:
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/SyncAPI.cpp
clang-tools-extra/clangd/unittests/SyncAPI.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 919d59ab09d0..cd6cba8c2ed3 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 7aed7d4f3d85..1bc7d70eebad 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -295,10 +295,6 @@ class ClangdServer {
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 7a7853a6245c..35e7fd72c3c5 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -238,10 +238,6 @@ class ReplayPreamble : private PPCallbacks {
} // 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 361b20aeff4c..05818b9dba80 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -146,10 +146,6 @@ class ParsedAST {
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 585fabe60ab7..a7c25683e9c1 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 c356fb08d5dd..fb810f40c79f 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 63a128d4ddcd..944717db4151 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);
More information about the cfe-commits
mailing list