From 0dee397e062bc170b80e4d25d936d5a411cfe32f Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Tue, 11 Sep 2018 10:31:38 +0000 Subject: [PATCH] [clangd] NFC: Use uint32_t for FuzzyFindRequest limits Reviewed By: ioeric Differential Revision: https://reviews.llvm.org/D51860 llvm-svn: 341921 --- clang-tools-extra/clangd/index/Index.cpp | 18 +++++++----------- clang-tools-extra/clangd/index/Index.h | 4 +++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/clang-tools-extra/clangd/index/Index.cpp b/clang-tools-extra/clangd/index/Index.cpp index c0c821a..5a8f0d1 100644 --- a/clang-tools-extra/clangd/index/Index.cpp +++ b/clang-tools-extra/clangd/index/Index.cpp @@ -177,29 +177,25 @@ std::shared_ptr SwapIndex::snapshot() const { bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request) { json::ObjectMapper O(Parameters); - llvm::Optional MaxCandidateCount; + int64_t MaxCandidateCount; bool OK = O && O.map("Query", Request.Query) && O.map("Scopes", Request.Scopes) && + O.map("MaxCandidateCount", MaxCandidateCount) && O.map("RestrictForCodeCompletion", Request.RestrictForCodeCompletion) && - O.map("ProximityPaths", Request.ProximityPaths) && - O.map("MaxCandidateCount", MaxCandidateCount); - if (MaxCandidateCount) - Request.MaxCandidateCount = MaxCandidateCount.getValue(); + O.map("ProximityPaths", Request.ProximityPaths); + if (OK && MaxCandidateCount <= std::numeric_limits::max()) + Request.MaxCandidateCount = MaxCandidateCount; return OK; } llvm::json::Value toJSON(const FuzzyFindRequest &Request) { - auto Result = json::Object{ + return json::Object{ {"Query", Request.Query}, {"Scopes", json::Array{Request.Scopes}}, + {"MaxCandidateCount", Request.MaxCandidateCount}, {"RestrictForCodeCompletion", Request.RestrictForCodeCompletion}, {"ProximityPaths", json::Array{Request.ProximityPaths}}, }; - // A huge limit means no limit, leave it out. - if (Request.MaxCandidateCount <= std::numeric_limits::max()) - Result["MaxCandidateCount"] = - static_cast(Request.MaxCandidateCount); - return std::move(Result); } bool SwapIndex::fuzzyFind(const FuzzyFindRequest &R, diff --git a/clang-tools-extra/clangd/index/Index.h b/clang-tools-extra/clangd/index/Index.h index b531d1e..c14ed9a 100644 --- a/clang-tools-extra/clangd/index/Index.h +++ b/clang-tools-extra/clangd/index/Index.h @@ -437,7 +437,9 @@ struct FuzzyFindRequest { std::vector Scopes; /// \brief The number of top candidates to return. The index may choose to /// return more than this, e.g. if it doesn't know which candidates are best. - size_t MaxCandidateCount = std::numeric_limits::max(); + // FIXME: Use llvm::Optional; semantically, the absence of MaxCandidateCount + // is equivalent to setting this field to default value as below. + uint32_t MaxCandidateCount = std::numeric_limits::max(); /// If set to true, only symbols for completion support will be considered. bool RestrictForCodeCompletion = false; /// Contextually relevant files (e.g. the file we're code-completing in). -- 2.7.4