提交 9587a6c3 编写于 作者: C Cyrus Najmabadi

Suppress inline hints when parameter name isn't important given hte method name.

上级 d53c1f47
......@@ -352,5 +352,137 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints
Await VerifyParamHints(input)
End Function
<WorkItem(47597, "https://github.com/dotnet/roslyn/issues/47597")>
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestNotOnEnableDisableBoolean1() As Task
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
class A
sub EnableLogging(value as boolean)
end sub
sub Main()
EnableLogging(true)
end sub
end class
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
<WorkItem(47597, "https://github.com/dotnet/roslyn/issues/47597")>
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestNotOnEnableDisableBoolean2() As Task
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
class A
sub DisableLogging(value as boolean)
end sub
sub Main()
DisableLogging(true)
end sub
end class
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
<WorkItem(47597, "https://github.com/dotnet/roslyn/issues/47597")>
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestOnEnableDisableNonBoolean1() As Task
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
class A
sub EnableLogging(value as string)
end sub
sub Main()
EnableLogging({|value:"IO"|})
end sub
end class
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
<WorkItem(47597, "https://github.com/dotnet/roslyn/issues/47597")>
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestOnEnableDisableNonBoolean2() As Task
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
class A
sub DisableLogging(value as string)
end sub
sub Main()
DisableLogging({|value:"IO"|})
end sub
end class
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
<WorkItem(47597, "https://github.com/dotnet/roslyn/issues/47597")>
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestOnSetMethodWithClearContext() As Task
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
class A
sub SetClassification(classification as string)
end sub
sub Main()
SetClassification("IO")
end sub
end class
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
<WorkItem(47597, "https://github.com/dotnet/roslyn/issues/47597")>
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestOnSetMethodWithUnclearContext() As Task
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
class A
sub SetClassification(values as string)
end sub
sub Main()
SetClassification({|values:"IO"|})
end sub
end class
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
End Class
End Namespace
......@@ -6,7 +6,6 @@ Imports System.Composition
Imports System.Threading
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.InlineHints
Imports Microsoft.CodeAnalysis.PooledObjects
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.InlineParameterNameHints
......@@ -27,17 +26,52 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.InlineParameterNameHints
hideForParametersThatMatchMethodIntent As Boolean,
CancellationToken As CancellationToken)
Dim simpleArgument = TryCast(node, SimpleArgumentSyntax)
If simpleArgument?.Expression IsNot Nothing Then
If Not simpleArgument.IsNamed AndAlso simpleArgument.NameColonEquals Is Nothing Then
Dim param = simpleArgument.DetermineParameter(semanticModel, allowParamArray:=False, CancellationToken)
If Not String.IsNullOrEmpty(param?.Name) Then
addHint(New InlineParameterHint(param.GetSymbolKey(CancellationToken), param.Name, simpleArgument.Span.Start, GetKind(simpleArgument.Expression)))
End If
End If
Dim argument = TryCast(node, SimpleArgumentSyntax)
If argument?.Expression Is Nothing Then
Return
End If
If argument.IsNamed OrElse argument.NameColonEquals IsNot Nothing Then
Return
End If
Dim parameter = argument.DetermineParameter(semanticModel, allowParamArray:=False, CancellationToken)
If String.IsNullOrEmpty(parameter?.Name) Then
Return
End If
If hideForParametersThatMatchMethodIntent AndAlso MatchesMethodIntent(argument, parameter) Then
Return
End If
addHint(New InlineParameterHint(parameter.GetSymbolKey(CancellationToken), parameter.Name, argument.Span.Start, GetKind(argument.Expression)))
End Sub
Private Overloads Shared Function MatchesMethodIntent(argument As ArgumentSyntax, parameter As IParameterSymbol) As Boolean
' Methods Like `SetColor(color: "y")` `FromResult(result: "x")` `Enable/DisablePolling(bool)` don't need
' parameter names to improve clarity. The parameter Is clear from the context of the method name.
Dim argumentList = TryCast(argument.Parent, ArgumentListSyntax)
If argumentList Is Nothing Then
Return False
End If
If argumentList.Arguments(0) IsNot argument Then
Return False
End If
Dim invocationExpression = TryCast(argumentList.Parent, InvocationExpressionSyntax)
If invocationExpression Is Nothing Then
Return False
End If
Dim rightMostName = invocationExpression.Expression.GetRightmostName()
If rightMostName Is Nothing Then
Return False
End If
Return AbstractInlineParameterNameHintsService.MatchesMethodIntent(rightMostName.Identifier.ValueText, parameter)
End Function
Private Function GetKind(arg As ExpressionSyntax) As InlineParameterHintKind
If TypeOf arg Is LiteralExpressionSyntax OrElse
TypeOf arg Is InterpolatedStringExpressionSyntax Then
......
......@@ -254,7 +254,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
End Function
<Extension>
Public Function GetRightmostName(node As ExpressionSyntax) As NameSyntax
Public Function GetRightmostName(node As ExpressionSyntax) As SimpleNameSyntax
Dim memberAccess = TryCast(node, MemberAccessExpressionSyntax)
If memberAccess IsNot Nothing AndAlso memberAccess.Name IsNot Nothing Then
Return memberAccess.Name
......@@ -265,12 +265,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return qualified.Right
End If
Dim simple = TryCast(node, SimpleNameSyntax)
If simple IsNot Nothing Then
Return simple
End If
Return Nothing
Return TryCast(node, SimpleNameSyntax)
End Function
<Extension>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册