Skip to content

Commit 8bee5c6

Browse files
committed
Disable limiting completion result.
Because vscode cache the include completion results. But for emacs, the json is too large to load. TODO Make some fields optional.
1 parent 9986ae5 commit 8bee5c6

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/clang_complete.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ unsigned Flags() {
2929

3030
unsigned GetCompletionPriority(const CXCompletionString& str,
3131
CXCursorKind result_kind,
32-
const std::string& typedText) {
32+
const optional<std::string>& typedText) {
3333
unsigned priority = clang_getCompletionPriority(str);
3434

3535
// XXX: What happens if priority overflows?
3636
if (result_kind == CXCursor_Destructor) {
3737
priority *= 100;
3838
}
3939
if (result_kind == CXCursor_ConversionFunction ||
40-
(result_kind == CXCursor_CXXMethod &&
41-
StartsWith(typedText, "operator"))) {
40+
(result_kind == CXCursor_CXXMethod && typedText &&
41+
StartsWith(*typedText, "operator"))) {
4242
priority *= 100;
4343
}
4444
if (clang_getCompletionAvailability(str) != CXAvailability_Available) {
@@ -193,7 +193,7 @@ void BuildCompletionItemTexts(std::vector<lsCompletionItem>& out,
193193

194194
for (auto i = out_first; i < out.size(); ++i) {
195195
// first typed text is used for filtering
196-
if (kind == CXCompletionChunk_TypedText && out[i].filterText.empty())
196+
if (kind == CXCompletionChunk_TypedText && !out[i].filterText)
197197
out[i].filterText = text;
198198

199199
if (kind == CXCompletionChunk_Placeholder)

src/language_server_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ struct lsCompletionItem {
364364

365365
// A string that should be used when filtering a set of
366366
// completion items. When `falsy` the label is used.
367-
std::string filterText;
367+
optional<std::string> filterText;
368368

369369
// A string that should be inserted a document when selecting
370370
// this completion. When `falsy` the label is used.

src/lex_utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void DecorateIncludePaths(const std::smatch& match,
8080
for (lsCompletionItem& item : *items) {
8181
item.textEdit->newText = prefix + item.textEdit->newText + suffix;
8282
item.label = prefix + item.label + suffix;
83-
item.filterText = item.label;
83+
item.filterText = nullopt;
8484
}
8585
}
8686

src/messages/initialize.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct lsCompletionOptions {
3838
// for
3939
// '::' and '>' for '->'. See
4040
// https://github.com/Microsoft/language-server-protocol/issues/138.
41-
std::vector<std::string> triggerCharacters = {".", ":", ">", "#", "<", "\""};
41+
std::vector<std::string> triggerCharacters = {".", ":", ">", "#", "<", "\"", "/"};
4242
};
4343
MAKE_REFLECT_STRUCT(lsCompletionOptions, resolveProvider, triggerCharacters);
4444

src/messages/text_document_completion.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ bool CompareLsCompletionItem(const lsCompletionItem& lhs,
7676
return lhs.skip_ < rhs.skip_;
7777
if (lhs.priority_ != rhs.priority_)
7878
return lhs.priority_ < rhs.priority_;
79-
if (lhs.filterText.length() != rhs.filterText.length())
80-
return lhs.filterText.length() < rhs.filterText.length();
81-
return lhs.filterText < rhs.filterText;
79+
if (lhs.filterText->length() != rhs.filterText->length())
80+
return lhs.filterText->length() < rhs.filterText->length();
81+
return *lhs.filterText < *rhs.filterText;
8282
}
8383

8484
template <typename T>
@@ -121,7 +121,7 @@ void FilterAndSortCompletionResponse(
121121

122122
auto& items = complete_response->result.items;
123123

124-
if (!enable) {
124+
if (!enable || complete_text.empty()) {
125125
// Just set the |sortText| to be the priority and return.
126126
char buf[16];
127127
for (auto& item : items)
@@ -130,17 +130,15 @@ void FilterAndSortCompletionResponse(
130130
}
131131

132132
// Make sure all items have |filterText| set, code that follow needs it.
133-
for (auto& item : items) {
134-
if (item.filterText.empty()) {
133+
for (auto& item : items)
134+
if (!item.filterText)
135135
item.filterText = item.label;
136-
}
137-
}
138136

139137
// If the text doesn't start with underscore,
140138
// remove all candidates that start with underscore.
141-
if (!complete_text.empty() && complete_text[0] != '_') {
139+
if (complete_text[0] != '_') {
142140
auto filter = [](const lsCompletionItem& item) {
143-
return item.filterText[0] == '_';
141+
return (*item.filterText)[0] == '_';
144142
};
145143
items.erase(std::remove_if(items.begin(), items.end(), filter),
146144
items.end());
@@ -150,7 +148,7 @@ void FilterAndSortCompletionResponse(
150148
bool found = false;
151149
for (auto& item : items) {
152150
std::tie(item.found_, item.skip_) =
153-
SubsequenceCountSkip(complete_text, item.filterText);
151+
SubsequenceCountSkip(complete_text, *item.filterText);
154152
found = found || item.found_;
155153
}
156154

@@ -179,10 +177,12 @@ void FilterAndSortCompletionResponse(
179177
for (size_t i = 0; i < items.size(); ++i)
180178
items[i].sortText = tofixedbase64(i, buf);
181179

182-
// If there are too many results...
183-
const size_t kMaxResultSize = 100u;
184-
if (items.size() > kMaxResultSize)
185-
items.resize(kMaxResultSize);
180+
// FIXME
181+
// The trigger behivour of vscode is puzzling.
182+
// So maybe it's not feasible to cut out any results.
183+
// const size_t kMaxResultSize = 100u;
184+
// if (items.size() > kMaxResultSize)
185+
// items.resize(kMaxResultSize);
186186
}
187187

188188
struct TextDocumentCompletionHandler : MessageHandler {
@@ -224,8 +224,8 @@ struct TextDocumentCompletionHandler : MessageHandler {
224224
std::string character = *request->params.context->triggerCharacter;
225225
char preceding_index = request->params.position.character - 2;
226226

227-
// If the character is '"' or '<', make sure that the line starts with '#'.
228-
if (character == "\"" || character == "<") {
227+
// If the character is '"', '<' or '/', make sure that the line starts with '#'.
228+
if (character == "\"" || character == "<" || character == "/") {
229229
size_t i = 0;
230230
while (i < buffer_line.size() && isspace(buffer_line[i]))
231231
++i;

0 commit comments

Comments
 (0)