未验证 提交 a0be2920 编写于 作者: J Jinu 提交者: GitHub

Merge pull request #30364 from Neme12/nullQuickInfo

Adding QuickInfo for null literal
......@@ -1243,6 +1243,22 @@ public async Task TestFalseKeyword()
MainDescription("struct System.Boolean"));
}
[WorkItem(26027, "https://github.com/dotnet/roslyn/issues/26027")]
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public async Task TestNullLiteral()
{
await TestInMethodAsync(@"string f = null$$",
MainDescription("class System.String"));
}
[WorkItem(26027, "https://github.com/dotnet/roslyn/issues/26027")]
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public async Task TestDefaultLiteral()
{
await TestInMethodAsync(@"string f = default$$",
MainDescription("class System.String"));
}
[WorkItem(756226, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/756226")]
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public async Task TestAwaitKeywordOnGenericTaskReturningAsync()
......
......@@ -108,6 +108,44 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Await TestCSharpAsync(workspace, $"({FeaturesResources.local_constant}) int x = 2")
End Function
<Fact>
Public Async Function TestCSharpNullLiteralVar() As Task
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class Goo
{
void Method()
{
var x = nu$$ll
}
}
</Document>
</Project>
</Workspace>
Await TestCSharpAsync(workspace, "")
End Function
<Fact>
Public Async Function TestCSharpNullLiteralString() As Task
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class Goo
{
void Method()
{
string x = nu$$ll
}
}
</Document>
</Project>
</Workspace>
Await TestCSharpAsync(workspace, "class System.String")
End Function
#End Region
#Region "Basic SymbolDescription Tests"
......@@ -508,9 +546,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Await TestBasicAsync(workspace, "Structure System.DateTime")
End Function
''' Design change from Dev10
<Fact>
Public Async Function TestNothingLiteral() As Task
Public Async Function TestNothingLiteralDim() As Task
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
......@@ -523,7 +560,40 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
</Document>
</Project>
</Workspace>
Await TestBasicAsync(workspace, "")
Await TestBasicAsync(workspace, "Class System.Object")
End Function
<Fact>
Public Async Function TestNothingLiteralDimAsString() As Task
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Class Goo
Sub Method()
Dim x As String = Nothin$$g
End Sub
End Class
</Document>
</Project>
</Workspace>
Await TestBasicAsync(workspace, "Class System.String")
End Function
<Fact>
Public Async Function TestNothingLiteralFieldDimOptionStrict() As Task
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Option Strict On
Class Goo
Dim x = Nothin$$g
End Class
</Document>
</Project>
</Workspace>
Await TestBasicAsync(workspace, "Class System.Object")
End Function
<Fact>
......
......@@ -1745,6 +1745,31 @@ End Class]]></text>.NormalizedValue(),
Text("cref."))))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
Public Async Function TestIntegerLiteral() As Task
Await TestInMethodAsync("Dim f = 37$$",
MainDescription("Structure System.Int32"))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
Public Async Function TestTrueKeyword() As Task
Await TestInMethodAsync("Dim f = True$$",
MainDescription("Structure System.Boolean"))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
Public Async Function TestFalseKeyword() As Task
Await TestInMethodAsync("Dim f = False$$",
MainDescription("Structure System.Boolean"))
End Function
<WorkItem(26027, "https://github.com/dotnet/roslyn/issues/26027")>
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
Public Async Function TestNothingLiteral() As Task
Await TestInMethodAsync("Dim f As String = Nothing$$",
MainDescription("Class System.String"))
End Function
''' <Remarks>
''' As a part of fix for 756226, quick info for VB Await keyword now displays the type inferred from the AwaitExpression. This is C# behavior.
''' In Dev12, quick info for VB Await keyword was the syntactic help "Await &lt;expression&gt;".
......
......@@ -16,12 +16,13 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions
internal struct TokenSemanticInfo
{
public static readonly TokenSemanticInfo Empty = new TokenSemanticInfo(
null, null, ImmutableArray<ISymbol>.Empty, null, default(TextSpan));
null, null, ImmutableArray<ISymbol>.Empty, null, null, default(TextSpan));
public readonly ISymbol DeclaredSymbol;
public readonly IAliasSymbol AliasSymbol;
public readonly ImmutableArray<ISymbol> ReferencedSymbols;
public readonly ITypeSymbol Type;
public readonly ITypeSymbol ConvertedType;
public readonly TextSpan Span;
public TokenSemanticInfo(
......@@ -29,12 +30,14 @@ internal struct TokenSemanticInfo
IAliasSymbol aliasSymbol,
ImmutableArray<ISymbol> referencedSymbols,
ITypeSymbol type,
ITypeSymbol convertedType,
TextSpan span)
{
DeclaredSymbol = declaredSymbol;
AliasSymbol = aliasSymbol;
ReferencedSymbols = referencedSymbols;
Type = type;
ConvertedType = convertedType;
Span = span;
}
......@@ -47,7 +50,7 @@ public ImmutableArray<ISymbol> GetSymbols(bool includeType)
if (includeType)
{
result.AddIfNotNull(Type);
result.AddIfNotNull(Type ?? ConvertedType);
}
return result.ToImmutableAndFree();
......@@ -179,6 +182,7 @@ private static ISymbol MapSymbol(ISymbol symbol, ITypeSymbol type)
{
IAliasSymbol aliasSymbol;
ITypeSymbol type;
ITypeSymbol convertedType;
ISymbol declaredSymbol;
ImmutableArray<ISymbol> allSymbols;
......@@ -192,6 +196,7 @@ private static ISymbol MapSymbol(ISymbol symbol, ITypeSymbol type)
// on an "override" token, the overridden symbol is the only part of TokenSemanticInfo used by callers, so type doesn't matter
type = null;
convertedType = null;
declaredSymbol = null;
allSymbols = overriddenSymbol is null ? ImmutableArray<ISymbol>.Empty : ImmutableArray.Create(overriddenSymbol);
}
......@@ -199,7 +204,9 @@ private static ISymbol MapSymbol(ISymbol symbol, ITypeSymbol type)
{
aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken);
var bindableParent = syntaxFacts.GetBindableParent(token);
type = semanticModel.GetTypeInfo(bindableParent, cancellationToken).Type;
var typeInfo = semanticModel.GetTypeInfo(bindableParent, cancellationToken);
type = typeInfo.Type;
convertedType = typeInfo.ConvertedType;
declaredSymbol = MapSymbol(semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken), type);
var skipSymbolInfoLookup = declaredSymbol.IsKind(SymbolKind.RangeVariable);
......@@ -238,9 +245,10 @@ private static ISymbol MapSymbol(ISymbol symbol, ITypeSymbol type)
if (allSymbols.Length == 0 && syntaxFacts.IsQueryKeyword(token))
{
type = null;
convertedType = null;
}
return new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type, token.Span);
return new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type, convertedType, token.Span);
}
public static SemanticModel GetOriginalSemanticModel(this SemanticModel semanticModel)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册