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

Fix issue with explicit interface completion and static interface members #76150

Merged
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 @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Completion.Providers;
Expand All @@ -14,7 +12,7 @@
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders;

[Trait(Traits.Feature, Traits.Features.Completion)]
public class ExplicitInterfaceTypeCompletionProviderTests : AbstractCSharpCompletionProviderTests
public sealed class ExplicitInterfaceTypeCompletionProviderTests : AbstractCSharpCompletionProviderTests
{
internal override Type GetCompletionProviderType()
=> typeof(ExplicitInterfaceTypeCompletionProvider);
Expand Down Expand Up @@ -358,4 +356,22 @@ class C<T> : I<T>

await VerifyItemExistsAsync(markup, "I", displayTextSuffix: "<>");
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/54005")]
public async Task TestWithStaticKeyword()
{
var markup = """
interface I1
{
static abstract void M1();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}

class C1 : I1
{
static void $$
}
""";

await VerifyItemExistsAsync(markup, "I1", displayTextSuffix: "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@

namespace Microsoft.CodeAnalysis.CSharp.Completion.Providers;

[ExportCompletionProvider(nameof(ExplicitInterfaceTypeCompletionProvider), LanguageNames.CSharp)]
[ExportCompletionProvider(nameof(ExplicitInterfaceTypeCompletionProvider), LanguageNames.CSharp), Shared]
[ExtensionOrder(After = nameof(ExplicitInterfaceMemberCompletionProvider))]
[Shared]
internal sealed partial class ExplicitInterfaceTypeCompletionProvider : AbstractSymbolCompletionProvider<CSharpSyntaxContext>
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed partial class ExplicitInterfaceTypeCompletionProvider() : AbstractSymbolCompletionProvider<CSharpSyntaxContext>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public ExplicitInterfaceTypeCompletionProvider()
{
}

internal override string Language => LanguageNames.CSharp;

public override bool IsInsertionTrigger(SourceText text, int insertedCharacterPosition, CompletionOptions options)
Expand Down Expand Up @@ -124,19 +119,14 @@ protected override Task<ImmutableArray<SymbolAndSelectionInfo>> GetSymbolsAsync(

private static bool IsPreviousTokenValid(SyntaxToken tokenBeforeType)
{
if (tokenBeforeType.Kind() == SyntaxKind.AsyncKeyword)
{
while (tokenBeforeType.Kind() is SyntaxKind.AsyncKeyword or SyntaxKind.StaticKeyword)
tokenBeforeType = tokenBeforeType.GetPreviousToken();
}

// Show us after the open brace for a class/struct/interface
if (tokenBeforeType.Kind() == SyntaxKind.OpenBraceToken)
{
// Show us after the open brace for a class/struct/interface
return IsClassOrStructOrInterfaceOrRecord(tokenBeforeType.GetRequiredParent());
}

if (tokenBeforeType.Kind() is SyntaxKind.CloseBraceToken or
SyntaxKind.SemicolonToken)
if (tokenBeforeType.Kind() is SyntaxKind.CloseBraceToken or SyntaxKind.SemicolonToken)
{
// Check that we're after a class/struct/interface member.
var memberDeclaration = tokenBeforeType.GetAncestor<MemberDeclarationSyntax>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace Microsoft.CodeAnalysis.Completion.Providers;
internal abstract partial class AbstractSymbolCompletionProvider<TSyntaxContext> : LSPCompletionProvider
where TSyntaxContext : SyntaxContext
{
protected AbstractSymbolCompletionProvider()
{
}

protected abstract (string displayText, string suffix, string insertionText) GetDisplayAndSuffixAndInsertionText(ISymbol symbol, TSyntaxContext context);

protected abstract Task<ImmutableArray<SymbolAndSelectionInfo>> GetSymbolsAsync(
Expand Down
Loading