diff options
author | Kirill Bobyrev <kbobyrev.opensource@gmail.com> | 2018-09-10 11:51:05 +0000 |
---|---|---|
committer | Kirill Bobyrev <kbobyrev.opensource@gmail.com> | 2018-09-10 11:51:05 +0000 |
commit | 09f00dcf69fd87d50e93eb5218f20ebdd8ec7a61 (patch) | |
tree | e82d75820106eb778064b9e326494b48fc604f27 /clang-tools-extra/clangd/index/Index.cpp | |
parent | 57b5966dad858f30fd3bbdf42ba560ef9382f0c2 (diff) | |
download | bcm5719-llvm-09f00dcf69fd87d50e93eb5218f20ebdd8ec7a61.tar.gz bcm5719-llvm-09f00dcf69fd87d50e93eb5218f20ebdd8ec7a61.zip |
[clangd] Implement FuzzyFindRequest JSON (de)serialization
JSON (de)serialization of `FuzzyFindRequest` might be useful for both
D51090 and D51628. Also, this allows precise logging of the fuzzy find
requests.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D51852
llvm-svn: 341802
Diffstat (limited to 'clang-tools-extra/clangd/index/Index.cpp')
-rw-r--r-- | clang-tools-extra/clangd/index/Index.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/Index.cpp b/clang-tools-extra/clangd/index/Index.cpp index a01c49f6573..013ba5cf9e7 100644 --- a/clang-tools-extra/clangd/index/Index.cpp +++ b/clang-tools-extra/clangd/index/Index.cpp @@ -175,6 +175,33 @@ std::shared_ptr<SymbolIndex> SwapIndex::snapshot() const { return Index; } +bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request) { + json::ObjectMapper O(Parameters); + llvm::Optional<int64_t> MaxCandidateCount; + bool OK = + O && O.map("Query", Request.Query) && O.map("Scopes", Request.Scopes) && + O.map("RestrictForCodeCompletion", Request.RestrictForCodeCompletion) && + O.map("ProximityPaths", Request.ProximityPaths) && + O.map("MaxCandidateCount", MaxCandidateCount); + if (MaxCandidateCount) + Request.MaxCandidateCount = MaxCandidateCount.getValue(); + return OK; +} + +llvm::json::Value toJSON(const FuzzyFindRequest &Request) { + auto Result = json::Object{ + {"Query", Request.Query}, + {"Scopes", json::Array{Request.Scopes}}, + {"RestrictForCodeCompletion", Request.RestrictForCodeCompletion}, + {"ProximityPaths", json::Array{Request.ProximityPaths}}, + }; + // A huge limit means no limit, leave it out. + if (Request.MaxCandidateCount <= std::numeric_limits<int64_t>::max()) + Result["MaxCandidateCount"] = + static_cast<int64_t>(Request.MaxCandidateCount); + return Result; +} + bool SwapIndex::fuzzyFind(const FuzzyFindRequest &R, llvm::function_ref<void(const Symbol &)> CB) const { return snapshot()->fuzzyFind(R, CB); |