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

CompletionService refactoring and small tweaks to import completion #59125

Merged
merged 22 commits into from
Feb 3, 2022

Conversation

genlu
Copy link
Member

@genlu genlu commented Jan 28, 2022

This is extracted from #59045.

Other than refactoring, there's also a few notable changes to the behavior of import completion (which lays the foundation for the additional changes in #59045):

  1. Returns partial result if cache is not fully populated (this is for unimported types, provider for unimported extension methods already does this)
  2. Selecting expander no longer force cache population and returning of complete result. Partial result will be returned if cache is not fully populated.
  3. Timebox (500ms) for unimported extension method provider is removed. This is not the intended final behavior, additonal change in Don't block completion for items from unimported namespaces #59045 would ensure completion do not block on import completion. This also fixed CancellationTokenSource disposed in AbstractExtensionMethodImportCompletionProvider.cs #58932
  4. Always show expander in the filter list. If we are not in the proper context or no expanded items would be available, then selecting it would be a no-op. This simplifies the implementation w/o (IMO) causing any UX issue.

Comment on lines 411 to 413
private readonly record struct VSCompletionItemData
(string DisplayText, ImageElement Icon, ImmutableArray<AsyncCompletionData.CompletionFilter> Filters,
int FilterSetData, ImmutableArray<ImageElement> AttributeIcons, string InsertionText);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to separate file. my pref on formatting would be:

        private readonly record struct VSCompletionItemData(
            string DisplayText,
            ImageElement Icon,
            ImmutableArray<AsyncCompletionData.CompletionFilter> Filters,
            int FilterSetData,
            ImmutableArray<ImageElement> AttributeIcons,
            string InsertionText);

Taht way all the properties are very clear.

Mask = mask;
}
}
private readonly record struct FilterWithMask(CompletionFilter Filter, int Mask);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move to separate file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That feels unnecessary to me, given this is a private, one-line auxiliary type. Is this required by our convention?

}

using var _ = ArrayBuilder<CompletionItemWithHighlight>.GetInstance(items.Count, out var builder);
builder.AddRange(items.Select(matchResult =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use SleectAsArray? i'm not sure how this new code is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

items is a pooled list, not an ImmutableArray, I think the overload of SelectAsArray for it doesn't create the instance of ArrayBuilder with a capacity. Give the potentially large size of this list, this would avoid call to EnsureCapacity thus reduce allocation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that eventually we'd want to avoid potentially LOH allocation here, by asking for a new API from editor so we don't need to realize any ImmutableArray, and use pooled object instead.

@@ -40,44 +39,42 @@ public Task NotifyCommittingItemAsync(Document document, CompletionItem item, ch

public override async Task ProvideCompletionsAsync(CompletionContext completionContext)
{
// Don't trigger import completion if the option value is "default" and the experiment is disabled for the user.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what experiment do we still have 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.

Import completion is still disabled by default, we use an experiment to turn it on for all internal users.

@@ -67,12 +66,10 @@ public Task WarmUpCacheAsync(Project? project, CancellationToken cancellationTok
s_cachingTask = Task.Run(() => WarmUpCacheAsync(workspace.CurrentSolution.GetProject(projectId), CancellationToken.None), CancellationToken.None);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you considered just using a AsyncBatchignWorkQueue instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into it, and change in a follow up PR if it's feasible.

@CyrusNajmabadi
Copy link
Member

i'm overall ok with this. my general feedback is similar to before. the refactorings are helping with complexity. but as you go inot methods have a strong eye toward doc'ing what is going on and making it so the methods are clearer in purpose and logic.

Since you're doing several PRs this can be slowly done as you do all the work. but ideally the end result is that all the individual pieces feel clearer and far less complex when people are workign with them.

thanks!

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved, with requests for some changes.

@genlu genlu enabled auto-merge February 2, 2022 23:25
@genlu genlu merged commit 1793f06 into dotnet:main Feb 3, 2022
@ghost ghost added this to the Next milestone Feb 3, 2022
@genlu genlu deleted the CompletionRefactoring branch February 3, 2022 00:08
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P1 Feb 4, 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.

CancellationTokenSource disposed in AbstractExtensionMethodImportCompletionProvider.cs
3 participants