Add completion.maxNum: 100

This commit is contained in:
Fangrui Song 2018-10-03 09:15:09 -07:00
parent 8b2565fcd0
commit 0c5c3a11be
3 changed files with 8 additions and 6 deletions

View File

@ -10,8 +10,6 @@
#include <clang/Lex/Lexer.h>
#include <llvm/Support/Path.h>
#include <mutex>
using namespace clang;
std::string PathFromFileEntry(const FileEntry &file) {

View File

@ -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,

View File

@ -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;
}