Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,37 @@ Select Case x
Select Case x
Case |
Case 1
</MethodBody>, "Else")
End Sub

<Fact>
<Trait(Traits.Feature, Traits.Features.KeywordRecommending)>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<WorkItem(...)>

Public Sub ElseWithinIfWithinElse()
VerifyRecommendationsContain(
<MethodBody>
If True Then

Else
If False Then
|
End If
End If
</MethodBody>, "Else")
End Sub

<Fact>
<Trait(Traits.Feature, Traits.Features.KeywordRecommending)>
Public Sub ElseWithinElseIfWithinElse()
VerifyRecommendationsContain(
<MethodBody>
If True Then

Else
If False Then
ElseIf True
|
End If
End If
</MethodBody>, "Else")
End Sub
End Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.Stat

If context.IsSingleLineStatementContext AndAlso
context.IsInStatementBlockOfKind(SyntaxKind.MultiLineIfBlock, SyntaxKind.ElseIfBlock) AndAlso
Not context.IsInStatementBlockOfKind(SyntaxKind.ElseBlock) Then
IsNotDirectlyInElseBlock(context) Then

Return SpecializedCollections.SingletonEnumerable(New RecommendedKeyword("Else", VBFeaturesResources.ElseKeywordToolTip))
End If
Expand All @@ -45,5 +45,23 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.Stat

Return SpecializedCollections.EmptyEnumerable(Of RecommendedKeyword)()
End Function

Private Function IsNotDirectlyInElseBlock(context As VisualBasicSyntaxContext) As Boolean

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the current implementation, this method name seems wrong ("directness" isn't required)

Dim parent = context.TargetToken.Parent
Do While parent IsNot Nothing
If parent.IsKind(SyntaxKind.MultiLineIfBlock, SyntaxKind.ElseIfBlock) Then
Return True
End If

If parent.IsKind(SyntaxKind.ElseBlock) Then
Return False
End If

parent = parent.Parent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where we actually have to go up multiple levels, or should this just look at parent and then stop?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we offer "Else" inside a more nested scope (say, a Do While loop) just because the Do While loop itself is in an If?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can just look at the parents of the TargetToken.

Loop

' We already know we're inside a Multiline If or ElseIf
Throw ExceptionUtilities.Unreachable
End Function
End Class
End Namespace