From 38feb8d277c3eeaa44e5ffa314637f5c0e6c3fd2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 3 Oct 2018 09:15:09 -0700 Subject: [PATCH] Add completion.maxNum: 100 --- src/clang_tu.cc | 2 -- src/config.h | 6 +++++- src/messages/textDocument_completion.cc | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/clang_tu.cc b/src/clang_tu.cc index f147b4c2..b58a69e9 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -22,8 +22,6 @@ limitations under the License. #include #include -#include - using namespace clang; std::string PathFromFileEntry(const FileEntry &file) { diff --git a/src/config.h b/src/config.h index 8889f94b..32d9fff6 100644 --- a/src/config.h +++ b/src/config.h @@ -130,6 +130,9 @@ struct Config { // that implement their own filtering and sorting logic. bool filterAndSort = true; + // Maxmum number of results. + int maxNum = 100; + struct Include { // Regex patterns to match include completion candidates against. They // receive the absolute file path. @@ -260,7 +263,8 @@ MAKE_REFLECT_STRUCT(Config::CodeLens, localVariables); MAKE_REFLECT_STRUCT(Config::Completion::Include, blacklist, maxPathSize, suffixWhitelist, whitelist); MAKE_REFLECT_STRUCT(Config::Completion, caseSensitivity, detailedLabel, - dropOldRequests, duplicateOptional, filterAndSort, include); + dropOldRequests, duplicateOptional, filterAndSort, include, + maxNum); MAKE_REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave, spellChecking, whitelist) MAKE_REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist, diff --git a/src/messages/textDocument_completion.cc b/src/messages/textDocument_completion.cc index 411e4763..daa6c7c3 100644 --- a/src/messages/textDocument_completion.cc +++ b/src/messages/textDocument_completion.cc @@ -182,9 +182,9 @@ void FilterAndSortCompletionResponse( auto &items = complete_response->result.items; auto finalize = [&]() { - const size_t kMaxResultSize = 100u; - if (items.size() > kMaxResultSize) { - items.resize(kMaxResultSize); + int max_num = g_config->completion.maxNum; + if (items.size() > max_num) { + items.resize(max_num); complete_response->result.isIncomplete = true; }