This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Proposal: improved completion results #391
Closed
Closed
Changes from all commits
Commits
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 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 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 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 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 |
---|---|---|
|
@@ -68,17 +68,16 @@ struct Out_TextDocumentComplete | |
}; | ||
MAKE_REFLECT_STRUCT(Out_TextDocumentComplete, jsonrpc, id, result); | ||
|
||
bool CompareLsCompletionItem(const lsCompletionItem& item1, | ||
const lsCompletionItem& item2) { | ||
if (item1.found_ != item2.found_) | ||
return item1.found_ > item2.found_; | ||
if (item1.skip_ != item2.skip_) | ||
return item1.skip_ < item2.skip_; | ||
if (item1.priority_ != item2.priority_) | ||
return item1.priority_ < item2.priority_; | ||
if (item1.label.length() != item2.label.length()) | ||
return item1.label.length() < item2.label.length(); | ||
return item1.label < item2.label; | ||
bool CompareLsCompletionItem(const lsCompletionItem& lhs, | ||
const lsCompletionItem& rhs) { | ||
const auto lhsFilterTextLength = lhs.filterText.length(); | ||
const auto lhsLabelLength = lhs.label.length(); | ||
const auto rhsFilterTextLength = rhs.filterText.length(); | ||
const auto rhsLabelLength = rhs.label.length(); | ||
return std::tie(lhs.found_, lhs.skip_, lhs.priority_, lhsFilterTextLength, | ||
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.
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. Thanks, good catch, unexpected last-minute merge. |
||
lhs.filterText, lhsLabelLength, lhs.label) < | ||
std::tie(rhs.found_, rhs.skip_, rhs.priority_, rhsFilterTextLength, | ||
rhs.filterText, rhsLabelLength, lhs.label); | ||
} | ||
|
||
template <typename T> | ||
|
@@ -129,11 +128,18 @@ void FilterAndSortCompletionResponse( | |
return; | ||
} | ||
|
||
// make sure all items have |filterText| set, code that follow needs it | ||
for (auto& item : items) { | ||
if (item.filterText.empty()) { | ||
item.filterText = item.label; | ||
} | ||
} | ||
|
||
// If the text doesn't start with underscore, | ||
// remove all candidates that start with underscore. | ||
if (!complete_text.empty() && complete_text[0] != '_') { | ||
auto filter = [](const lsCompletionItem& item) { | ||
return item.label[0] == '_'; | ||
return item.filterText[0] == '_'; | ||
}; | ||
items.erase(std::remove_if(items.begin(), items.end(), filter), | ||
items.end()); | ||
|
@@ -142,7 +148,7 @@ void FilterAndSortCompletionResponse( | |
// Fuzzy match. | ||
for (auto& item : items) | ||
std::tie(item.found_, item.skip_) = | ||
SubsequenceCountSkip(complete_text, item.label); | ||
SubsequenceCountSkip(complete_text, item.filterText); | ||
|
||
// Order all items and set |sortText|. | ||
std::sort(items.begin(), items.end(), CompareLsCompletionItem); | ||
|
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.
line 168 contains
Can they be less duplicated
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.
Not sure to understand, what do you mean?
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.
There is another chunk of code below where these character branches (
case CXCompletionChunk_LeftParen
) and string literalstext = '('
are duplicated