@@ -115,6 +115,25 @@ class CompletionRequest {
115
115
CompletionRequest (llvm::StringRef command_line, unsigned raw_cursor_pos,
116
116
CompletionResult &result);
117
117
118
+ // / Constructs a completion request.
119
+ // /
120
+ // / \param [in] command_line
121
+ // / The command line the user has typed at this point.
122
+ // /
123
+ // / \param [in] raw_cursor_pos
124
+ // / The position of the cursor in the command line string. Index 0 means
125
+ // / the cursor is at the start of the line. The completion starts from
126
+ // / this cursor position.
127
+ // /
128
+ // / \param [in] max_return_elements
129
+ // / The maximum number of completions that should be returned.
130
+ // /
131
+ // / \param [out] result
132
+ // / The CompletionResult that will be filled with the results after this
133
+ // / request has been handled.
134
+ CompletionRequest (llvm::StringRef command_line, unsigned raw_cursor_pos,
135
+ size_t max_return_elements, CompletionResult &result);
136
+
118
137
// / Returns the raw user input used to create this CompletionRequest cut off
119
138
// / at the cursor position. The cursor will be at the end of the raw line.
120
139
llvm::StringRef GetRawLine () const {
@@ -157,6 +176,23 @@ class CompletionRequest {
157
176
158
177
size_t GetCursorIndex () const { return m_cursor_index; }
159
178
179
+ size_t GetMaxReturnElements () const { return m_max_return_elements; }
180
+
181
+ // / Returns true if the maximum number of completions has been reached
182
+ // / already.
183
+ bool ShouldStopAddingResults () const {
184
+ return m_result.GetNumberOfResults () >= m_max_return_elements;
185
+ }
186
+
187
+ // / Returns the maximum number of completions that need to be added
188
+ // / until reaching the maximum
189
+ size_t GetMaxNumberOfResultsToAdd () const {
190
+ const size_t number_of_results = m_result.GetNumberOfResults ();
191
+ if (number_of_results >= m_max_return_elements)
192
+ return 0 ;
193
+ return m_max_return_elements - number_of_results;
194
+ }
195
+
160
196
// / Adds a possible completion string. If the completion was already
161
197
// / suggested before, it will not be added to the list of results. A copy of
162
198
// / the suggested completion is stored, so the given string can be free'd
@@ -231,6 +267,8 @@ class CompletionRequest {
231
267
size_t m_cursor_index;
232
268
// / The cursor position in the argument indexed by m_cursor_index.
233
269
size_t m_cursor_char_position;
270
+ // / The maximum number of completions that should be returned.
271
+ size_t m_max_return_elements;
234
272
235
273
// / The result this request is supposed to fill out.
236
274
// / We keep this object private to ensure that no backend can in any way
0 commit comments