-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Remove editor item from MatchResult #64229
Conversation
And use MatchResult for filtering in CompletionService API so we have more information to work with across API boundary
{ | ||
public readonly RoslynCompletionItem RoslynCompletionItem; | ||
public readonly CompletionItem CompletionItem; |
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.
We don't actually need to keep a reference to editor item anymore. It can be found using IndexInOriginalSortedOrder
isntead.
string filterText, | ||
IList<CompletionItem> builder) | ||
IList<MatchResult> builder) |
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.
Now we simply return a subset of MatchResult
s passed in, this would provide more information across the API boundry and simplify the implementation.
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.
consider updating comment
string filterText, | ||
IList<CompletionItem> builder) | ||
IList<MatchResult> builder) |
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.
We probably should deprecate the public version of this and promote this to public
@@ -140,12 +140,16 @@ private bool ShouldSelectSuggestionItemWhenNoItemMatchesFilterText | |||
if (itemsToBeIncluded.Count == 0) | |||
return HandleAllItemsFilteredOut(); | |||
|
|||
var highlightAndFilterTask = Task.Run( |
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.
This is the only one of two behavior changes in this PR, we now calculate highlight and filter states in parallel to item selection.
private static readonly ObjectPool<List<MatchResult<VSCompletionItem>>> s_listOfMatchResultPool = new(factory: () => new()); | ||
private static readonly ObjectPool<List<(RoslynCompletionItem, PatternMatch?)>> s_listOfItemMatchPairPool = new(factory: () => new()); | ||
private static readonly ObjectPool<List<RoslynCompletionItem>> s_filteredItemBuilderPool = new(factory: () => new()); | ||
private static readonly ObjectPool<List<MatchResult>> s_listOfMatchResultPool = new(factory: () => new()); |
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.
eliminated two object pools with this change
5b35dd2
to
6938c2b
Compare
IList<CompletionItem> builder) | ||
=> FilterItemsImpl(document, itemsWithPatternMatch, filterText, builder); | ||
IList<MatchResult> builder) | ||
=> FilterItemsImpl(document, matchResults, filterText, builder); | ||
|
||
internal virtual void FilterItemsImpl( |
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.
TS isn't using this at the moment, so we can change it w/o breaking them. We should move them off the public one though since it's not performant
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.
I have verified that TS completion is still working properly with this PR
when everything else are considered equal
UniqueItem: moreThanOneMatch || !bestMatchResult.HasValue ? null : bestMatchResult.Value.EditorCompletionItem); | ||
UniqueItem: moreThanOneMatch || !bestMatchResult.HasValue ? null : GetCorrespondingVsCompletionItem(bestMatchResult.Value, cancellationToken)); | ||
|
||
static int CompareForDeletion(MatchResult x, MatchResult y, string pattern) |
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.
This is moved here from type MatchResult, since this is the only usage.
if ((currentItemPriority > bestItemPriority) || | ||
((currentItemPriority == bestItemPriority) && !bestItem.IsPreferredItem() && chosenItem.IsPreferredItem())) | ||
// final preference is match to FilterText over AdditionalFilterTexts | ||
if (bestResult.MatchedWithAdditionalFilterTexts && !currentResult.MatchedWithAdditionalFilterTexts) |
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.
This is another behavior change in this PR. if everything else considered equal (see comments in the code above), we will select item that matches FilterText
over the one matches AdditionalFilterTexts
.
This should have very limited effect at the moment, since only a few semantic snippet items actually use AdditionalFilterTexts
. My goal is to centralize the filtering logic for all items that requires multiple filtertext (e.g. enum members), which is now buried in random matching logics and very hard to find.
@@ -123,7 +123,7 @@ private static SegmentedList<VSCompletionItem> SortCompletionitems(AsyncCompleti | |||
} | |||
|
|||
var updater = new CompletionListUpdater(session.ApplicableToSpan, sessionData, data, _recentItemsManager, _globalOptions); | |||
return updater.UpdateCompletionList(session, cancellationToken); | |||
return await updater.UpdateCompletionListAsync(session, cancellationToken).ConfigureAwait(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.
Would it make sense instead to give the await configuration control to the caller by just returning the task and removing the async in the signature?
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.
I have to await a task in the code above (line 107) though
string filterText, | ||
IList<CompletionItem> builder) | ||
IList<MatchResult> builder) |
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.
consider updating comment
|
||
/// <summary> | ||
/// The actual editor completion item associated with this <see cref="RoslynCompletionItem"/> | ||
/// In VS for example, this is the associated VS async completion item. | ||
/// If `CompletionItem.AdditionalFilterTexts` was used to create this MatchResult, then this is set to the one that was used. |
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.
Im not familiar with our comment pattern yet. Would cref be appropriate here?
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.
yup, I definitely need to buff up the doc-comment in this type
And a few other clean-ups