Skip to content
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

Merged
merged 8 commits into from
Sep 23, 2022
Merged

Remove editor item from MatchResult #64229

merged 8 commits into from
Sep 23, 2022

Conversation

genlu
Copy link
Member

@genlu genlu commented Sep 22, 2022

And a few other clean-ups

And use MatchResult for filtering in CompletionService API so we have more information to work with across API boundary
@genlu genlu requested a review from a team as a code owner September 22, 2022 21:33
{
public readonly RoslynCompletionItem RoslynCompletionItem;
public readonly CompletionItem CompletionItem;
Copy link
Member Author

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)
Copy link
Member Author

@genlu genlu Sep 22, 2022

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 MatchResults passed in, this would provide more information across the API boundry and simplify the implementation.

Copy link
Member

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)
Copy link
Member Author

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(
Copy link
Member Author

@genlu genlu Sep 22, 2022

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());
Copy link
Member Author

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

IList<CompletionItem> builder)
=> FilterItemsImpl(document, itemsWithPatternMatch, filterText, builder);
IList<MatchResult> builder)
=> FilterItemsImpl(document, matchResults, filterText, builder);

internal virtual void FilterItemsImpl(
Copy link
Member Author

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

Copy link
Member Author

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

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)
Copy link
Member Author

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)
Copy link
Member Author

@genlu genlu Sep 23, 2022

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);
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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.
Copy link
Member

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?

Copy link
Member Author

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

@genlu genlu merged commit 60ef17d into dotnet:main Sep 23, 2022
@genlu genlu deleted the RemoveEditorItem branch September 23, 2022 19:04
@ghost ghost added this to the Next milestone Sep 23, 2022
@Cosifne Cosifne modified the milestones: Next, 17.4 P3 Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants