Skip to content

Commit

Permalink
Merge pull request #59125 from genlu/CompletionRefactoring
Browse files Browse the repository at this point in the history
CompletionService refactoring and small tweaks to import completion
  • Loading branch information
genlu authored Feb 3, 2022
2 parents 29e1ec8 + 817f5d8 commit 1793f06
Show file tree
Hide file tree
Showing 47 changed files with 719 additions and 914 deletions.
2 changes: 1 addition & 1 deletion eng/config/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ T:Microsoft.VisualStudio.Shell.Interop.IComWrapper; Use Microsoft.VisualStudio.L
P:Microsoft.CodeAnalysis.Completion.CompletionContext.Options; Use CompletionOptions instead.
M:Microsoft.CodeAnalysis.Completion.CompletionProvider.ShouldTriggerCompletion(Microsoft.CodeAnalysis.Text.SourceText,System.Int32,Microsoft.CodeAnalysis.Completion.CompletionTrigger,Microsoft.CodeAnalysis.Options.OptionSet); Use internal overload instead
M:Microsoft.CodeAnalysis.Completion.CompletionProvider.GetDescriptionAsync(Microsoft.CodeAnalysis.Document,Microsoft.CodeAnalysis.Completion.CompletionItem,System.Threading.CancellationToken); Use internal overload instead
M:Microsoft.CodeAnalysis.Completion.CompletionService.GetCompletionsAsync(Microsoft.CodeAnalysis.Document,System.Int32,Microsoft.CodeAnalysis.Completion.CompletionTrigger,System.Collections.Immutable.ImmutableHashSet{System.String},Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use GetCompletionsInternalAsync instead
M:Microsoft.CodeAnalysis.Completion.CompletionService.GetCompletionsAsync(Microsoft.CodeAnalysis.Document,System.Int32,Microsoft.CodeAnalysis.Completion.CompletionTrigger,System.Collections.Immutable.ImmutableHashSet{System.String},Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use internal overload instead
M:Microsoft.CodeAnalysis.Completion.CompletionService.GetDescriptionAsync(Microsoft.CodeAnalysis.Document,Microsoft.CodeAnalysis.Completion.CompletionItem,System.Threading.CancellationToken); Use internal overload instead
M:Microsoft.CodeAnalysis.Completion.CompletionService.GetRules; Use internal overload instead
M:Microsoft.CodeAnalysis.QuickInfo.QuickInfoService.GetQuickInfoAsync(Microsoft.CodeAnalysis.Document,System.Int32,System.Threading.CancellationToken); Use internal overload instead
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Completion.Providers;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.Data;
using Roslyn.Test.Utilities;
Expand All @@ -27,8 +25,7 @@ public class ExtensionMethodImportCompletionProviderTests : AbstractCSharpComple
public ExtensionMethodImportCompletionProviderTests()
{
ShowImportCompletionItemsOptionValue = true;
TimeoutInMilliseconds = -1; // -1 disables timeout
IsExpandedCompletion = true;
ForceExpandedCompletionIndexCreation = true;
}

internal override Type GetCompletionProviderType()
Expand Down Expand Up @@ -1933,44 +1930,6 @@ public void M()
await VerifyProviderCommitAsync(markup, "ToInt", expected, commitChar: commitChar, sourceCodeKind: SourceCodeKind.Regular);
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task TestTimeBox()
{
var file1 = @"
using System;
namespace Foo
{
public static class ExtensionClass
{
public static bool ExtentionMethod(this int x)
=> true;
}
}";
var file2 = @"
using System;
namespace Baz
{
public class Bat
{
public void M(int x)
{
x.$$
}
}
}";

IsExpandedCompletion = false;
TimeoutInMilliseconds = 0; //timeout immediately
var markup = GetMarkup(file2, file1, ReferenceType.None);

await VerifyImportItemIsAbsentAsync(
markup,
"ExtentionMethod",
inlineDescription: "Foo");
}

[InlineData("int", true, "int a")]
[InlineData("int[]", true, "int a, int b")]
[InlineData("bool", false, null)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ private async Task VerifyExclusiveAsync(string markup, bool exclusive)
var service = GetCompletionService(document.Project);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);

if (completionList != null)
if (!completionList.IsEmpty)
{
Assert.True(exclusive == completionList.GetTestAccessor().IsExclusive, "group.IsExclusive == " + completionList.GetTestAccessor().IsExclusive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ string Property
var service = CompletionService.GetService(document);
var options = CompletionOptions.Default;
var displayOptions = SymbolDescriptionOptions.Default;
var (completions, _) = await service.GetCompletionsInternalAsync(document, position, options);
var completions = await service.GetCompletionsAsync(document, position, options);

var item = completions.Items.First(i => i.DisplayText == "Beep");
var edit = testDocument.GetTextBuffer().CreateEdit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp.Completion.Providers;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand All @@ -27,7 +25,7 @@ internal override Type GetCompletionProviderType()
public TypeImportCompletionProviderTests()
{
ShowImportCompletionItemsOptionValue = true;
IsExpandedCompletion = true;
ForceExpandedCompletionIndexCreation = true;
}

#region "Option tests"
Expand All @@ -52,7 +50,7 @@ class Bar
public async Task OptionSetToNull_ExpDisabled()
{
ShowImportCompletionItemsOptionValue = null;
IsExpandedCompletion = false;
ForceExpandedCompletionIndexCreation = false;
var markup = @"
class Bar
{
Expand All @@ -69,7 +67,7 @@ public async Task OptionSetToFalse(bool isExperimentEnabled)
{
TypeImportCompletionFeatureFlag = isExperimentEnabled;
ShowImportCompletionItemsOptionValue = false;
IsExpandedCompletion = false;
ForceExpandedCompletionIndexCreation = false;

var markup = @"
class Bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class C1
// We want to make sure import completion providers are also participating.
var options = CompletionOptions.From(document.Project.Solution.Options, document.Project.Language);
var newOptions = options with { ShowItemsFromUnimportedNamespaces = true };
var (completionList, _) = await compeltionService.GetCompletionsInternalAsync(document, position.Value, options: newOptions);
var completionList = await compeltionService.GetCompletionsAsync(document, position.Value, options: newOptions);

// We expect completion to run on frozen partial semantic, which won't run source generator.
Assert.Equal(0, generatorRanCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Completion.Providers;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
Expand Down Expand Up @@ -119,7 +118,7 @@ public AsyncCompletionData.CommitResult TryCommit(
var serviceRules = completionService.GetRules(options);

// We can be called before for ShouldCommitCompletion. However, that call does not provide rules applied for the completion item.
// Now we check for the commit charcter in the context of Rules that could change the list of commit characters.
// Now we check for the commit character in the context of Rules that could change the list of commit characters.

if (!Helpers.IsStandardCommitCharacter(typeChar) && !IsCommitCharacter(serviceRules, roslynItem, typeChar))
{
Expand Down Expand Up @@ -198,7 +197,7 @@ private AsyncCompletionData.CommitResult Commit(

CompletionChange change;

// We met an issue when external code threw an OperationCanceledException and the cancellationToken is not cancelled.
// We met an issue when external code threw an OperationCanceledException and the cancellationToken is not canceled.
// Catching this scenario for further investigations.
// See https://github.com/dotnet/roslyn/issues/38455.
try
Expand Down Expand Up @@ -241,7 +240,7 @@ private AsyncCompletionData.CommitResult Commit(

if (change.NewPosition.HasValue)
{
// Roslyn knows how to positionate the caret in the snapshot we just created.
// Roslyn knows how to position the caret in the snapshot we just created.
// If there were more edits made by extensions, TryMoveCaretToAndEnsureVisible maps the snapshot point to the most recent one.
view.TryMoveCaretToAndEnsureVisible(new SnapshotPoint(updatedCurrentSnapshot, change.NewPosition.Value));
}
Expand Down Expand Up @@ -271,7 +270,7 @@ private AsyncCompletionData.CommitResult Commit(
if (roslynItem.Rules.FormatOnCommit)
{
// The edit updates the snapshot however other extensions may make changes there.
// Therefore, it is required to use subjectBuffer.CurrentSnapshot for further calculations rather than the updated current snapsot defined above.
// Therefore, it is required to use subjectBuffer.CurrentSnapshot for further calculations rather than the updated current snapshot defined above.
var currentDocument = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
var formattingService = currentDocument?.GetRequiredLanguageService<IFormattingInteractionService>();

Expand Down Expand Up @@ -312,7 +311,7 @@ private AsyncCompletionData.CommitResult Commit(

internal static bool IsCommitCharacter(CompletionRules completionRules, CompletionItem item, char ch)
{
// First see if the item has any specifc commit rules it wants followed.
// First see if the item has any specific commit rules it wants followed.
foreach (var rule in item.Rules.CommitCharacterRules)
{
switch (rule.Kind)
Expand Down
Loading

0 comments on commit 1793f06

Please sign in to comment.