-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb] returning command completions up to a maximum #135565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JDevlieghere
merged 3 commits into
llvm:main
from
eronnen:lldb-completions-return-up-to-maximum
Apr 23, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,11 @@ class CompletionRequest { | |
| CompletionRequest(llvm::StringRef command_line, unsigned raw_cursor_pos, | ||
| CompletionResult &result); | ||
|
|
||
| /// Sets the maximum number of completions that should be returned. | ||
| void SetMaxReturnElements(size_t max_return_elements) { | ||
| m_max_return_elements = max_return_elements; | ||
| } | ||
|
|
||
| /// Returns the raw user input used to create this CompletionRequest cut off | ||
| /// at the cursor position. The cursor will be at the end of the raw line. | ||
| llvm::StringRef GetRawLine() const { | ||
|
|
@@ -157,6 +162,23 @@ class CompletionRequest { | |
|
|
||
| size_t GetCursorIndex() const { return m_cursor_index; } | ||
|
|
||
| size_t GetMaxReturnElements() const { return m_max_return_elements; } | ||
|
|
||
| /// Returns true if the maximum number of completions has not been reached | ||
| /// yet, hence we should keep adding completions. | ||
| bool ShouldAddCompletions() const { | ||
| return GetMaxNumberOfCompletionsToAdd() > 0; | ||
| } | ||
|
|
||
| /// Returns the maximum number of completions that need to be added | ||
| /// until reaching the maximum | ||
| size_t GetMaxNumberOfCompletionsToAdd() const { | ||
| const size_t number_of_results = m_result.GetNumberOfResults(); | ||
| if (number_of_results >= m_max_return_elements) | ||
| return 0; | ||
| return m_max_return_elements - number_of_results; | ||
| } | ||
|
|
||
| /// Adds a possible completion string. If the completion was already | ||
| /// suggested before, it will not be added to the list of results. A copy of | ||
| /// the suggested completion is stored, so the given string can be free'd | ||
|
|
@@ -231,6 +253,8 @@ class CompletionRequest { | |
| size_t m_cursor_index; | ||
| /// The cursor position in the argument indexed by m_cursor_index. | ||
| size_t m_cursor_char_position; | ||
| /// The maximum number of completions that should be returned. | ||
| size_t m_max_return_elements = std::numeric_limits<size_t>::max(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a sensible (non size_t max) default? |
||
|
|
||
| /// The result this request is supposed to fill out. | ||
| /// We keep this object private to ensure that no backend can in any way | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this just call
ShouldAddCompletions()and return 0 if false?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But still it needs to return the number of completions if
ShouldAddCompletionsis trueI Changed
ShouldAddCompletionsto returnGetMaxNumberOfCompletionsToAdd > 0instead in order to reuse code