提交 0fa63cd5 编写于 作者: D David Poeschl

Show QuickInfo on references to indexers

Fixes #38283
上级 f1f2f517
......@@ -6678,5 +6678,55 @@ void M(string[] a)
await TestInClassAsync(code,
MainDescription($"({FeaturesResources.range_variable}) IGrouping<int, string> g"));
}
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
[WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")]
public async Task QuickInfoOnIndexerCloseBracket()
{
await TestAsync(@"
class C
{
public int this[int x] { get { return 1; } }
void M()
{
var x = new C()[5$$];
}
}",
MainDescription("int C.this[int x] { get; }"));
}
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
[WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")]
public async Task QuickInfoOnIndexerOpenBracket()
{
await TestAsync(@"
class C
{
public int this[int x] { get { return 1; } }
void M()
{
var x = new C()$$[5];
}
}",
MainDescription("int C.this[int x] { get; }"));
}
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
[WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")]
public async Task QuickInfoOnIndexer_NotOnArrayAccess()
{
await TestAsync(@"
class Program
{
void M()
{
int[] x = new int[4];
int y = x[3$$];
}
}",
MainDescription("struct System.Int32"));
}
}
}
......@@ -2439,5 +2439,68 @@ Class C
End Class",
Documentation("Summary for property Goo"))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")>
Public Async Function QuickInfoOnIndexerOpenParen() As Task
Await TestAsync("
Class C
Default Public ReadOnly Property Item(ByVal index As Integer) As Integer
Get
Return 1
End Get
End Property
Sub M()
Dim x = New C()
Dim y = x$$(4)
End Sub
End Class",
MainDescription("ReadOnly Property C.Item(index As Integer) As Integer"))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")>
Public Async Function QuickInfoOnIndexerCloseParen() As Task
Await TestAsync("
Class C
Default Public ReadOnly Property Item(ByVal index As Integer) As Integer
Get
Return 1
End Get
End Property
Sub M()
Dim x = New C()
Dim y = x(4$$)
End Sub
End Class",
MainDescription("ReadOnly Property C.Item(index As Integer) As Integer"))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")>
Public Async Function QuickInfoOnIndexer_MissingOnRegularMethodCall() As Task
Await TestAsync("
Class C
Sub M()
M($$)
End Sub
End Class",
Nothing)
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(38283, "https://github.com/dotnet/roslyn/issues/38283")>
Public Async Function QuickInfoOnIndexer_MissingOnArrayAccess() As Task
Await TestAsync("
Class C
Sub M()
Dim x(4) As Integer
Dim y = x(3$$)
End Sub
End Class",
MainDescription("Structure System.Int32"))
End Function
End Class
End Namespace
......@@ -42,6 +42,19 @@ protected override bool GetBindableNodeForTokenIndicatingLambda(SyntaxToken toke
return false;
}
protected override bool GetBindableNodeForTokenIndicatingPossibleIndexerAccess(SyntaxToken token, out SyntaxNode found)
{
if (token.IsKind(SyntaxKind.CloseBracketToken, SyntaxKind.OpenBracketToken) &&
token.Parent?.Parent.IsKind(SyntaxKind.ElementAccessExpression) == true)
{
found = token.Parent.Parent;
return true;
}
found = null;
return false;
}
protected override bool ShouldCheckPreviousToken(SyntaxToken token)
{
return !token.Parent.IsKind(SyntaxKind.XmlCrefAttribute);
......
......@@ -303,6 +303,7 @@ void AddSection(string kind, ImmutableArray<TaggedText> taggedParts)
}
protected abstract bool GetBindableNodeForTokenIndicatingLambda(SyntaxToken token, out SyntaxNode found);
protected abstract bool GetBindableNodeForTokenIndicatingPossibleIndexerAccess(SyntaxToken token, out SyntaxNode found);
protected virtual ImmutableArray<TaggedText> TryGetNullabilityAnalysis(Workspace workspace, SemanticModel semanticModel, SyntaxToken token, CancellationToken cancellationToken) => default;
......@@ -313,16 +314,7 @@ void AddSection(string kind, ImmutableArray<TaggedText> taggedParts)
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var enclosingType = semanticModel.GetEnclosingNamedType(token.SpanStart, cancellationToken);
ImmutableArray<ISymbol> symbols;
if (GetBindableNodeForTokenIndicatingLambda(token, out var lambdaSyntax))
{
symbols = ImmutableArray.Create(semanticModel.GetSymbolInfo(lambdaSyntax).Symbol);
}
else
{
symbols = semanticModel.GetSemanticInfo(token, document.Project.Solution.Workspace, cancellationToken)
.GetSymbols(includeType: true);
}
var symbols = GetSymbolsFromToken(token, document.Project.Solution.Workspace, semanticModel, cancellationToken);
var bindableParent = syntaxFacts.GetBindableParent(token);
var overloads = semanticModel.GetMemberGroup(bindableParent, cancellationToken);
......@@ -353,6 +345,26 @@ void AddSection(string kind, ImmutableArray<TaggedText> taggedParts)
return (semanticModel, ImmutableArray<ISymbol>.Empty);
}
private ImmutableArray<ISymbol> GetSymbolsFromToken(SyntaxToken token, Workspace workspace, SemanticModel semanticModel, CancellationToken cancellationToken)
{
if (GetBindableNodeForTokenIndicatingLambda(token, out var lambdaSyntax))
{
return ImmutableArray.Create(semanticModel.GetSymbolInfo(lambdaSyntax, cancellationToken).Symbol);
}
if (GetBindableNodeForTokenIndicatingPossibleIndexerAccess(token, out var elementAccessExpression))
{
var symbol = semanticModel.GetSymbolInfo(elementAccessExpression, cancellationToken).Symbol;
if (symbol?.IsIndexer() == true)
{
return ImmutableArray.Create(symbol);
}
}
return semanticModel.GetSemanticInfo(token, workspace, cancellationToken)
.GetSymbols(includeType: true);
}
private static bool IsOk(ISymbol symbol)
=> symbol != null && !symbol.IsErrorType();
......
......@@ -106,6 +106,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.QuickInfo
Return False
End Function
Protected Overrides Function GetBindableNodeForTokenIndicatingPossibleIndexerAccess(token As SyntaxToken, ByRef found As SyntaxNode) As Boolean
If token.IsKind(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken) AndAlso
token.Parent?.Parent.IsKind(SyntaxKind.InvocationExpression) = True Then
found = token.Parent.Parent
Return True
End If
found = Nothing
Return False
End Function
Private Overloads Async Function BuildContentAsync(
document As Document,
token As SyntaxToken,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册