From af6ba7d756ac9785a27d7edf75214bd619274c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Tue, 1 Nov 2011 15:58:59 +0100 Subject: [PATCH] Fixed unit test. --- .../Completion/CSharpCompletionEngine.cs | 11 +++- .../CodeCompletion/ObjectInitializerTests.cs | 51 +++++++++++++++++-- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index 5438df8c44..bb439b8c16 100644 --- a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -413,8 +413,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion var contextList = new CompletionDataWrapper (this); var identifierStart = GetExpressionAtCursor (); - if (!(char.IsLetter (completionChar) || completionChar == '_') && (identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) + if (!(char.IsLetter (completionChar) || completionChar == '_') && (!controlSpace || identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) { return controlSpace ? HandleAccessorContext () ?? DefaultControlSpaceItems () : null; + } + char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : '\0'; char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' '; const string allowedChars = ";,[(){}+-*/%^?:&|~!<>="; @@ -431,7 +433,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return null; } } - if (identifierStart == null) return HandleAccessorContext () ?? DefaultControlSpaceItems (); @@ -1596,8 +1597,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } baseUnit = ParseStub ("a()"); + // Hack for handle object initializer continuation expressions + if (baseUnit.GetNodeAt (location) is AttributedNode) { + baseUnit = ParseStub ("a()};"); + } + var memberLocation = currentMember != null ? currentMember.Region.Begin : currentType.Region.Begin; var mref = baseUnit.GetNodeAt (location); + if (mref == null){ var invoke = baseUnit.GetNodeAt (location); if (invoke != null) diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs index 44be84d300..3b5d0ae523 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs @@ -185,7 +185,7 @@ class test { public void testcc () { foo f = new foo () { - $$ + $b$ }; } } @@ -203,7 +203,7 @@ class test { public void TestBug1745 () { CodeCompletionBugTests.CombinedProviderTest ( - + @"class Test { public int TF1 { get; set; } } @@ -218,7 +218,52 @@ class CCTest { Assert.IsNull (provider.Find ("TF1")); Assert.IsNotNull (provider.Find ("Test")); }); - } + } + + [Test()] + public void TestBugAfterBracketContext () + { + var provider = CodeCompletionBugTests.CreateProvider ( +@"class Test { + public int TF1 { get; set; } +} + +class CCTest { + void TestMethod () + { + $new Test () {$ + } +} +"); + Assert.IsTrue (provider == null || provider.Count == 0); + } + + /// + /// Bug 487236 - Object initializer completion uses wrong type + /// + [Test()] + public void TestObjectInitializerContinuation () + { + CodeCompletionBugTests.CombinedProviderTest ( +@" +public class A +{ + public string Name { get; set; } +} + +class MyTest +{ + static string Str = ""hello""; + + public void Test () + { + $var x = new A () { Name = MyTest.$ + } +} +", provider => { + Assert.IsNotNull (provider.Find ("Str"), "field 'Str' not found."); + }); + } } }