Skip to content

Commit

Permalink
Merge pull request #69855 from genlu/DoNotCrash
Browse files Browse the repository at this point in the history
Handle non-member-overriding context in OverrideCompletion
  • Loading branch information
genlu authored Sep 9, 2023
2 parents 8673196 + b77bed4 commit 7016360
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3508,6 +3508,27 @@ class D : C
""", "M()");
}

[WpfFact, WorkItem("https://github.com/dotnet/vscode-csharp/issues/6308")]
public async Task NoOverrideItemsWhenNotInTypeDeclaration()
{
await VerifyNoItemsExistAsync("""
namespace NS
{
override $$
}
""");
}

[WpfFact, WorkItem("https://github.com/dotnet/vscode-csharp/issues/6308")]
public async Task NoOverrideItemsAtTopLevel()
{
await VerifyNoItemsExistAsync("""
System.Console.WriteLine();

override $$
""");
}

private Task VerifyItemExistsAsync(string markup, string expectedItem)
{
return VerifyItemExistsAsync(markup, expectedItem, isComplexTextEdit: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Completion.Providers
{
Expand Down Expand Up @@ -111,7 +110,11 @@ private bool TryDetermineOverridableMembers(
out ImmutableArray<ISymbol> overridableMembers)
{
var containingType = semanticModel.GetEnclosingSymbol<INamedTypeSymbol>(startToken.SpanStart, _cancellationToken);
Contract.ThrowIfNull(containingType);
if (containingType is null)
{
overridableMembers = default;
return false;
}

var result = containingType.GetOverridableMembers(_cancellationToken);

Expand Down

0 comments on commit 7016360

Please sign in to comment.