Skip to content

Update suggestion mode provider to support params collections #76177

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

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders;

[Trait(Traits.Feature, Traits.Features.Completion)]
public class SuggestionModeCompletionProviderTests : AbstractCSharpCompletionProviderTests
public sealed class SuggestionModeCompletionProviderTests : AbstractCSharpCompletionProviderTests
{
internal override Type GetCompletionProviderType()
=> typeof(CSharpSuggestionModeCompletionProvider);
Expand Down Expand Up @@ -817,16 +817,17 @@ class C {
await VerifyBuilderAsync(markup);
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/72225")]
[WorkItem("https://github.com/dotnet/roslyn/issues/72225")]
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72225")]
public async Task UnwrapParamsCollection()
{
var markup = """
using System;
using System.Collections.Generic;

class C {
C(params IEnumerable<Action<int>> a) {
class C
{
C(params IEnumerable<Action<int>> a)
{
new C($$
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ End Class
Await TestAsync(input, expected)
End Function

<Fact(Skip:="https://github.com/dotnet/roslyn/issues/72227")>
<WorkItem("https://github.com/dotnet/roslyn/issues/72227")>
<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72227")>
Public Async Function Test_IndexerWithNoRequiredParameters_02() As Task
Dim input =
<Workspace>
Expand Down Expand Up @@ -257,8 +256,8 @@ Imports System.Collections.Generic

Class C
Implements I
Public ReadOnly Property Item(y As IEnumerable(Of Integer)) As Integer Implements I.Item

Default Public ReadOnly Property Item(y As IEnumerable(Of Integer)) As Integer Implements I.Item
Get
Throw New NotImplementedException()
End Get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
Expand All @@ -19,17 +20,12 @@

namespace Microsoft.CodeAnalysis.CSharp.Completion.Providers;

[ExportCompletionProvider(nameof(CSharpSuggestionModeCompletionProvider), LanguageNames.CSharp)]
[ExportCompletionProvider(nameof(CSharpSuggestionModeCompletionProvider), LanguageNames.CSharp), Shared]
[ExtensionOrder(After = nameof(ObjectAndWithInitializerCompletionProvider))]
[Shared]
internal class CSharpSuggestionModeCompletionProvider : AbstractSuggestionModeCompletionProvider
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal class CSharpSuggestionModeCompletionProvider() : AbstractSuggestionModeCompletionProvider
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpSuggestionModeCompletionProvider()
{
}

internal override string Language => LanguageNames.CSharp;

protected override async Task<CompletionItem?> GetSuggestionModeItemAsync(
Expand Down Expand Up @@ -190,9 +186,20 @@ token.Parent is TupleExpressionSyntax tupleExpression &&
private static ITypeSymbol? GetDelegateType(TypeInferenceInfo typeInferenceInfo, Compilation compilation)
{
var typeSymbol = typeInferenceInfo.InferredType;
if (typeInferenceInfo.IsParams && typeInferenceInfo.InferredType.IsArrayType())
if (typeInferenceInfo.IsParams)
{
typeSymbol = ((IArrayTypeSymbol)typeInferenceInfo.InferredType).ElementType;
if (typeInferenceInfo.InferredType.IsSpanOrReadOnlySpan())
{
typeSymbol = typeInferenceInfo.InferredType.GetTypeArguments().Single();
}
else
{
var ienumerableType = typeInferenceInfo.InferredType
.GetAllInterfacesIncludingThis()
.FirstOrDefault(i => i.OriginalDefinition.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T);
if (ienumerableType != null)
typeSymbol = ienumerableType.TypeArguments.Single();
}
}

return typeSymbol.GetDelegateType(compilation);
Expand Down
Loading