From 0c5c3a11be0a74a151618f10a6452e1b4a534265 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 ef717981..9812799b 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -10,8 +10,6 @@ #include #include -#include - using namespace clang; std::string PathFromFileEntry(const FileEntry &file) { diff --git a/src/config.h b/src/config.h index 2e9ce8ee..a463bd2a 100644 --- a/src/config.h +++ b/src/config.h @@ -118,6 +118,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. @@ -248,7 +251,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 2b62af70..4a301ec2 100644 --- a/src/messages/textDocument_completion.cc +++ b/src/messages/textDocument_completion.cc @@ -170,9 +170,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; }