forked from OSchip/llvm-project
[clangd] Express dumpAST in tests as a customAction()
This commit is contained in:
parent
44587e2f7e
commit
41d0edd54e
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue