Skip to content

Commit 3c84aee

Browse files
committed
Return the bound node names
1 parent ce1f6de commit 3c84aee

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ void ClangdLSPServer::onCommandApplyRename(const RenameParams &R,
856856
void ClangdLSPServer::onMethodSearchAST(const SearchASTArgs &Args,
857857
Callback<llvm::json::Value> Reply) {
858858
Server->findAST(Args, [Reply = std::move(Reply)](
859-
llvm::Expected<std::vector<std::vector<ASTNode>>>
859+
llvm::Expected<BoundASTNodes>
860860
BoundNodes) mutable {
861861
if (!BoundNodes)
862862
return Reply(BoundNodes.takeError());

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ void ClangdServer::locateSymbolAt(PathRef File, Position Pos,
811811
}
812812

813813
void ClangdServer::findAST(SearchASTArgs const &Args,
814-
Callback<std::vector<std::vector<ASTNode>>> CB) {
814+
Callback<BoundASTNodes> CB) {
815815
auto Action =
816816
[Args, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
817817
if (!InpAST)
@@ -824,19 +824,17 @@ void ClangdServer::findAST(SearchASTArgs const &Args,
824824

825825
auto &&AST = InpAST->AST;
826826
// Convert BoundNodes to a vector of vectors to ASTNode's.
827-
std::vector<std::vector<ASTNode>> Result;
827+
BoundASTNodes Result;
828828
Result.reserve(BoundNodes->size());
829829
for (auto &&BN : *BoundNodes) {
830830
auto &&Map = BN.getMap();
831-
std::vector<ASTNode> Nodes;
832-
Nodes.reserve(Map.size());
831+
BoundASTNodes::value_type BAN;
833832
for (const auto &[Key, Value] : Map) {
834-
auto Node = dumpAST(Value, AST.getTokens(), AST.getASTContext());
835-
Nodes.push_back(std::move(Node));
833+
BAN.emplace(Key, dumpAST(Value, AST.getTokens(), AST.getASTContext()));
836834
}
837-
if (Nodes.empty())
835+
if (BAN.empty())
838836
continue;
839-
Result.push_back(std::move(Nodes));
837+
Result.push_back(std::move(BAN));
840838
}
841839
if (Result.empty()) {
842840
return CB(error("No AST nodes found for the query"));

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/ADT/FunctionExtras.h"
3838
#include "llvm/ADT/StringRef.h"
3939
#include <functional>
40+
#include <map>
4041
#include <memory>
4142
#include <optional>
4243
#include <string>
@@ -263,7 +264,7 @@ class ClangdServer {
263264
Callback<std::vector<LocatedSymbol>> CB);
264265

265266
void findAST(const SearchASTArgs &Args,
266-
Callback<std::vector<std::vector<ASTNode>>> CB);
267+
Callback<BoundASTNodes> CB);
267268

268269
/// Switch to a corresponding source file when given a header file, and vice
269270
/// versa.

clang-tools-extra/clangd/Protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ struct SearchASTArgs {
14631463
static auto constexpr Tk = TraversalKind::TK_IgnoreUnlessSpelledInSource;
14641464
};
14651465
bool fromJSON(const llvm::json::Value &, SearchASTArgs &, llvm::json::Path);
1466+
using BoundASTNodes = std::vector<std::map<std::string, struct ASTNode>>;
14661467

14671468
struct PrepareRenameResult {
14681469
/// Range of the string to rename.

llvm/include/llvm/Support/JSON.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class Object {
111111
// (using std::pair forces extra copies).
112112
struct KV;
113113
explicit Object(std::initializer_list<KV> Properties);
114+
template <typename Collection> explicit Object(Collection &&C) {
115+
for (auto &&P : C)
116+
M.insert(P);
117+
}
114118

115119
iterator begin() { return M.begin(); }
116120
const_iterator begin() const { return M.begin(); }

0 commit comments

Comments
 (0)