@@ -91,7 +91,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
91
91
nullptr } // This one has to be last in the list.
92
92
};
93
93
94
- for (int i = 0 ;; i++) {
94
+ for (int i = 0 ; request. ShouldAddCompletions () ; i++) {
95
95
if (common_completions[i].type == lldb::eTerminatorCompletion)
96
96
break ;
97
97
else if ((common_completions[i].type & completion_mask) ==
@@ -167,7 +167,9 @@ class SourceFileCompleter : public Completer {
167
167
m_matching_files.AppendIfUnique (context.comp_unit ->GetPrimaryFile ());
168
168
}
169
169
}
170
- return Searcher::eCallbackReturnContinue;
170
+ return m_matching_files.GetSize () >= m_request.GetMaxNumberOfCompletionsToAdd ()
171
+ ? Searcher::eCallbackReturnStop
172
+ : Searcher::eCallbackReturnContinue;
171
173
}
172
174
173
175
void DoCompletion (SearchFilter *filter) override {
@@ -230,6 +232,9 @@ class SymbolCompleter : public Completer {
230
232
231
233
// Now add the functions & symbols to the list - only add if unique:
232
234
for (const SymbolContext &sc : sc_list) {
235
+ if (m_match_set.size () >= m_request.GetMaxNumberOfCompletionsToAdd ())
236
+ break ;
237
+
233
238
ConstString func_name = sc.GetFunctionName (Mangled::ePreferDemangled);
234
239
// Ensure that the function name matches the regex. This is more than
235
240
// a sanity check. It is possible that the demangled function name
@@ -239,7 +244,9 @@ class SymbolCompleter : public Completer {
239
244
m_match_set.insert (func_name);
240
245
}
241
246
}
242
- return Searcher::eCallbackReturnContinue;
247
+ return m_match_set.size () >= m_request.GetMaxNumberOfCompletionsToAdd ()
248
+ ? Searcher::eCallbackReturnStop
249
+ : Searcher::eCallbackReturnContinue;
243
250
}
244
251
245
252
void DoCompletion (SearchFilter *filter) override {
@@ -305,7 +312,8 @@ class ModuleCompleter : public Completer {
305
312
m_request.AddCompletion (cur_file_name);
306
313
}
307
314
}
308
- return Searcher::eCallbackReturnContinue;
315
+ return m_request.ShouldAddCompletions () ? Searcher::eCallbackReturnContinue
316
+ : Searcher::eCallbackReturnStop;
309
317
}
310
318
311
319
void DoCompletion (SearchFilter *filter) override { filter->Search (*this ); }
@@ -429,7 +437,8 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
429
437
std::error_code EC;
430
438
llvm::vfs::directory_iterator Iter = fs.DirBegin (SearchDir, EC);
431
439
llvm::vfs::directory_iterator End;
432
- for (; Iter != End && !EC; Iter.increment (EC)) {
440
+ for (; Iter != End && !EC && request.ShouldAddCompletions ();
441
+ Iter.increment (EC)) {
433
442
auto &Entry = *Iter;
434
443
llvm::ErrorOr<llvm::vfs::Status> Status = fs.GetStatus (Entry.path ());
435
444
0 commit comments