Browse Source

Fixed completion bug.

pull/32/merge
Mike Krüger 12 years ago
parent
commit
9b2bd8059e
  1. 35
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 38
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

35
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -1830,24 +1830,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1830,24 +1830,25 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (location [2]), Roles.LBrace), Roles.LBrace);
SwitchSection newSection = null;
bool lastWasCase = false, added = true;
foreach (var child in switchStatement.Block.Statements) {
var statement = child.Accept(this);
var caseLabel = statement as CaseLabel;
if (caseLabel != null) {
if (!lastWasCase) {
newSection = new SwitchSection();
added = false;
}
newSection.AddChild (caseLabel, SwitchSection.CaseLabelRole);
lastWasCase = true;
} else {
if (lastWasCase) {
result.AddChild (newSection, SwitchStatement.SwitchSectionRole);
lastWasCase = false;
added = true;
if (switchStatement.Block != null) {
foreach (var child in switchStatement.Block.Statements) {
var statement = child.Accept(this);
var caseLabel = statement as CaseLabel;
if (caseLabel != null) {
if (!lastWasCase) {
newSection = new SwitchSection();
added = false;
}
newSection.AddChild (caseLabel, SwitchSection.CaseLabelRole);
lastWasCase = true;
} else {
if (lastWasCase) {
result.AddChild (newSection, SwitchStatement.SwitchSectionRole);
lastWasCase = false;
added = true;
}
newSection.AddChild((Statement)statement, Roles.EmbeddedStatement);
}
newSection.AddChild((Statement)statement, Roles.EmbeddedStatement);
}
}
if (!added)

38
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -6019,6 +6019,44 @@ public class Testing @@ -6019,6 +6019,44 @@ public class Testing
Assert.AreEqual(0, provider.Count);
}
[Test]
public void TestSwitchCase ()
{
CombinedProviderTest(
@"using System;
class Test
{
public void Test (ConsoleColor color)
{
$switch (c$
}
}
", provider => {
Assert.IsNotNull(provider.Find("color"));
});
}
[Test]
public void TestSwitchCaseCase ()
{
CombinedProviderTest(
@"using System;
class Test
{
public void Test (ConsoleColor color)
{
switch (color) {
$case $
}
}
}
", provider => {
Assert.IsNotNull(provider.Find("ConsoleColor"));
});
}
}
}

Loading…
Cancel
Save