@@ -115,6 +115,11 @@ class CompletionRequest {
115115 CompletionRequest (llvm::StringRef command_line, unsigned raw_cursor_pos,
116116 CompletionResult &result);
117117
118+ // / Sets the maximum number of completions that should be returned.
119+ void SetMaxReturnElements (size_t max_return_elements) {
120+ m_max_return_elements = max_return_elements;
121+ }
122+
118123 // / Returns the raw user input used to create this CompletionRequest cut off
119124 // / at the cursor position. The cursor will be at the end of the raw line.
120125 llvm::StringRef GetRawLine () const {
@@ -157,6 +162,23 @@ class CompletionRequest {
157162
158163 size_t GetCursorIndex () const { return m_cursor_index; }
159164
165+ size_t GetMaxReturnElements () const { return m_max_return_elements; }
166+
167+ // / Returns true if the maximum number of completions has been reached
168+ // / already.
169+ bool ShouldStopAddingResults () const {
170+ return m_result.GetNumberOfResults () >= m_max_return_elements;
171+ }
172+
173+ // / Returns the maximum number of completions that need to be added
174+ // / until reaching the maximum
175+ size_t GetMaxNumberOfResultsToAdd () const {
176+ const size_t number_of_results = m_result.GetNumberOfResults ();
177+ if (number_of_results >= m_max_return_elements)
178+ return 0 ;
179+ return m_max_return_elements - number_of_results;
180+ }
181+
160182 // / Adds a possible completion string. If the completion was already
161183 // / suggested before, it will not be added to the list of results. A copy of
162184 // / the suggested completion is stored, so the given string can be free'd
@@ -231,6 +253,8 @@ class CompletionRequest {
231253 size_t m_cursor_index;
232254 // / The cursor position in the argument indexed by m_cursor_index.
233255 size_t m_cursor_char_position;
256+ // / The maximum number of completions that should be returned.
257+ size_t m_max_return_elements = SIZE_MAX;
234258
235259 // / The result this request is supposed to fill out.
236260 // / We keep this object private to ensure that no backend can in any way
0 commit comments