Skip to content

Commit

Permalink
Fix issue with explicit interface completion and static interface mem…
Browse files Browse the repository at this point in the history
…bers (#76150)
  • Loading branch information
CyrusNajmabadi authored Dec 2, 2024
2 parents fd6b931 + 0e605da commit 6afcc0a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
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();
}
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

0 comments on commit 6afcc0a

Please sign in to comment.