diff --git a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index ab03a26f85..6b5e237958 100644 --- a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -440,7 +440,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion if (!(char.IsLetter (completionChar) || completionChar == '_') && (!controlSpace || identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) { return controlSpace ? HandleAccessorContext () ?? DefaultControlSpaceItems (identifierStart) : null; } - char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : ';'; char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' '; const string allowedChars = ";,[](){}+-*/%^?:&|~!<>="; @@ -470,6 +469,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } CSharpResolver csResolver; AstNode n = identifierStart.Item2; + + if (n != null && n.Parent is AnonymousTypeCreateExpression) { + AutoSelect = false; + } + // Handle foreach (type name _ if (n is IdentifierExpression) { var prev = n.GetPrevNode () as ForeachStatement; @@ -2019,10 +2023,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion // try expression in anonymous type "new { sample = x$" case if (expr == null) { - baseUnit = ParseStub ("a };", false); + baseUnit = ParseStub ("a", false); + Print (baseUnit); expr = baseUnit.GetNodeAt (location.Line, location.Column); if (expr != null) - expr = baseUnit.GetNodeAt (location.Line, location.Column); + expr = baseUnit.GetNodeAt (location.Line, location.Column) ?? expr; } if (expr == null) diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs index 3492e7b6ea..57b6f89401 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs @@ -402,12 +402,13 @@ class A { public static void Main (string[] args) { - $from a in args select new { tes$ + Test($from a in args select new { t$); } } "); - Assert.IsTrue(provider == null || provider.Count == 0); // <--- here 0 item in the completion list + Assert.IsNotNull(provider); + Assert.IsFalse (provider.AutoSelect ); } [Test()] @@ -427,6 +428,7 @@ class A "); Assert.IsNotNull(provider); // <--- here 0 item in the completion list + Assert.IsTrue (provider.AutoSelect ); Assert.IsNotNull(provider.Find("a"), "'a' not found"); Assert.IsNotNull(provider.Find("new"), "'new' not found"); Assert.IsNotNull(provider.Find("args"), "'args' not found");