mirror of
https://github.com/MaskRay/ccls.git
synced 2025-08-20 21:52:23 +00:00
completion: delete insertText; don't set filterText if it is the same as label
On a `std::` completion case, it decreases Content-Length: from 32K to 25K
This commit is contained in:
parent
9fb17be2cd
commit
b66625e078
@ -122,7 +122,6 @@ struct CompletionItem {
|
|||||||
std::optional<std::string> documentation;
|
std::optional<std::string> documentation;
|
||||||
std::string sortText;
|
std::string sortText;
|
||||||
std::optional<std::string> filterText;
|
std::optional<std::string> filterText;
|
||||||
std::string insertText;
|
|
||||||
InsertTextFormat insertTextFormat = InsertTextFormat::PlainText;
|
InsertTextFormat insertTextFormat = InsertTextFormat::PlainText;
|
||||||
TextEdit textEdit;
|
TextEdit textEdit;
|
||||||
std::vector<TextEdit> additionalTextEdits;
|
std::vector<TextEdit> additionalTextEdits;
|
||||||
|
@ -35,8 +35,8 @@ using namespace llvm;
|
|||||||
MAKE_REFLECT_TYPE_PROXY(InsertTextFormat);
|
MAKE_REFLECT_TYPE_PROXY(InsertTextFormat);
|
||||||
MAKE_REFLECT_TYPE_PROXY(CompletionItemKind);
|
MAKE_REFLECT_TYPE_PROXY(CompletionItemKind);
|
||||||
MAKE_REFLECT_STRUCT(CompletionItem, label, kind, detail, documentation,
|
MAKE_REFLECT_STRUCT(CompletionItem, label, kind, detail, documentation,
|
||||||
sortText, filterText, insertText, insertTextFormat,
|
sortText, filterText, insertTextFormat, textEdit,
|
||||||
textEdit, additionalTextEdits);
|
additionalTextEdits);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct CompletionList {
|
struct CompletionList {
|
||||||
@ -141,11 +141,11 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
|||||||
}
|
}
|
||||||
edits.erase(edits.begin());
|
edits.erase(edits.begin());
|
||||||
}
|
}
|
||||||
|
if (item.filterText == item.label)
|
||||||
|
item.filterText.reset();
|
||||||
for (auto i = sort.size(); i && ++sort[i - 1] == 'A';)
|
for (auto i = sort.size(); i && ++sort[i - 1] == 'A';)
|
||||||
sort[--i] = ' ';
|
sort[--i] = ' ';
|
||||||
item.sortText = sort;
|
item.sortText = sort;
|
||||||
// Compatibility
|
|
||||||
item.insertText = item.textEdit.newText;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,19 +155,13 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure all items have |filterText| set, code that follow needs it.
|
|
||||||
for (auto &item : items) {
|
|
||||||
if (!item.filterText)
|
|
||||||
item.filterText = item.label;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fuzzy match and remove awful candidates.
|
// Fuzzy match and remove awful candidates.
|
||||||
bool sensitive = g_config->completion.caseSensitivity;
|
bool sensitive = g_config->completion.caseSensitivity;
|
||||||
FuzzyMatcher fuzzy(complete_text, sensitive);
|
FuzzyMatcher fuzzy(complete_text, sensitive);
|
||||||
for (auto &item : items) {
|
for (CompletionItem &item : items) {
|
||||||
item.score_ =
|
const std::string &filter = item.filterText ? *item.filterText : item.label;
|
||||||
ReverseSubseqMatch(complete_text, *item.filterText, sensitive) >= 0
|
item.score_ = ReverseSubseqMatch(complete_text, filter, sensitive) >= 0
|
||||||
? fuzzy.Match(*item.filterText)
|
? fuzzy.Match(filter)
|
||||||
: FuzzyMatcher::kMinScore;
|
: FuzzyMatcher::kMinScore;
|
||||||
}
|
}
|
||||||
items.erase(std::remove_if(items.begin(), items.end(),
|
items.erase(std::remove_if(items.begin(), items.end(),
|
||||||
@ -185,9 +179,9 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
|||||||
return lhs.score_ > rhs.score_;
|
return lhs.score_ > rhs.score_;
|
||||||
if (lhs.priority_ != rhs.priority_)
|
if (lhs.priority_ != rhs.priority_)
|
||||||
return lhs.priority_ < rhs.priority_;
|
return lhs.priority_ < rhs.priority_;
|
||||||
if (lhs.filterText->size() != rhs.filterText->size())
|
if (lhs.label.size() != rhs.label.size())
|
||||||
return lhs.filterText->size() < rhs.filterText->size();
|
return lhs.label.size() < rhs.label.size();
|
||||||
return *lhs.filterText < *rhs.filterText;
|
return lhs.label < rhs.label;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trim result.
|
// Trim result.
|
||||||
|
Loading…
Reference in New Issue
Block a user