提交 04a4404f 编写于 作者: P Paul Chen

Fix scope blocks within switch section.

上级 8c72941b
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
......@@ -65,7 +66,7 @@ internal class SyntacticQuickInfoProvider : AbstractQuickInfoProvider
// If the parent is a scope block, check and include nearby comments around the open brace
// LeadingTrivia is preferred
if (parent.IsKind(SyntaxKind.Block) && (parent.Parent.IsKind(SyntaxKind.Block) || parent.Parent.IsKind(SyntaxKind.GlobalStatement)))
if (IsScopeBlock(parent))
{
MarkInterestedSpanNearbyScopeBlock(parent, openBrace, ref spanStart, ref spanEnd);
}
......@@ -89,6 +90,16 @@ internal class SyntacticQuickInfoProvider : AbstractQuickInfoProvider
return this.CreateElisionBufferDeferredContent(span);
}
private static bool IsScopeBlock(SyntaxNode node)
{
var parent = node.Parent;
return node.IsKind(SyntaxKind.Block)
&& (parent.IsKind(SyntaxKind.Block)
|| parent.IsKind(SyntaxKind.SwitchSection)
|| parent.IsKind(SyntaxKind.GlobalStatement
));
}
private static void MarkInterestedSpanNearbyScopeBlock(SyntaxNode block, SyntaxToken openBrace, ref int spanStart, ref int spanEnd)
{
SyntaxTrivia nearbyComment;
......
......@@ -39,19 +39,19 @@ public void Brackets_0()
[WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public void Brackets_1()
{
TestInClass("int Property { get; }$$", "int Property {");
TestInClass("int Property { get; }$$ ", "int Property {");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public void Brackets_2()
{
TestInClass("void M()\r\n{ }$$", "void M()\r\n{");
TestInClass("void M()\r\n{ }$$ ", "void M()\r\n{");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public void Brackets_3()
{
TestInMethodAndScript("var a = new int[] { }$$", "new int[] {");
TestInMethodAndScript("var a = new int[] { }$$ ", "new int[] {");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
......@@ -173,7 +173,7 @@ public void ScopeBrackets_5()
public void ScopeBrackets_6()
{
TestInMethodAndScript(@"
for (;;;)
for (;;)
{
/*************/
......@@ -255,6 +255,24 @@ int Property
"{");
}
[WorkItem(325, "https://github.com/dotnet/roslyn/issues/325")]
[WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public void ScopeBrackets_10()
{
TestInMethodAndScript(@"
switch (true)
{
default:
// comment
{
}$$
break;
}
",
@"// comment
{");
}
private IQuickInfoProvider CreateProvider(TestWorkspace workspace)
{
return new SyntacticQuickInfoProvider(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册