From 2a795ae27065312286561f53263163883205db57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Tue, 25 Oct 2011 13:32:53 +0200 Subject: [PATCH] Fixed some unit tests. --- .../Completion/CSharpCompletionEngine.cs | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index f573799fd9..9fba783e8d 100644 --- a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -349,12 +349,17 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return null; } - return HandleKeywordCompletion (tokenIndex, token); + var keywordCompletion = HandleKeywordCompletion (tokenIndex, token); + if (keywordCompletion == null && controlSpace) + goto default; + return keywordCompletion; // Automatic completion default: if (IsInsideComment () || IsInsideString ()) return null; - if (!(char.IsLetter (completionChar) || completionChar == '_')) + var identifierStart = GetExpressionAtCursor (); + + if (!(char.IsLetter (completionChar) || completionChar == '_') && (identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) return controlSpace ? DefaultControlSpaceItems () : null; char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : '\0'; char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' '; @@ -372,12 +377,29 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return null; } - var identifierStart = GetExpressionAtCursor (); if (identifierStart == null) return null; + CSharpResolver csResolver; AstNode n = identifierStart.Item2; var contextList = new CompletionDataWrapper (this); + if (n is ArrayInitializerExpression) { + var initalizerResult = ResolveExpression (identifierStart.Item1, n.Parent, identifierStart.Item3); + if (initalizerResult != null) { + foreach (var property in initalizerResult.Item1.Type.GetProperties (ctx)) { + if (!property.IsPublic) + continue; + contextList.AddMember (property); + } + foreach (var field in initalizerResult.Item1.Type.GetProperties (ctx)){ + if (!field.IsPublic) + continue; + contextList.AddMember (field); + } + return contextList.Result; + } + return null; + } if (n != null/* && !(identifierStart.Item2 is TypeDeclaration)*/) { csResolver = new CSharpResolver (ctx, System.Threading.CancellationToken.None); @@ -1501,16 +1523,22 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } var baseUnit = ParseStub (""); - AstNode expr = baseUnit.GetNodeAt (location.Line, location.Column - 1); if (expr == null) expr = baseUnit.GetNodeAt (location.Line, location.Column - 1); if (expr == null) { baseUnit = ParseStub ("()"); expr = baseUnit.GetNodeAt (location.Line, location.Column - 1); - if (expr == null) - return null; } + + // try initializer expression + if (expr == null) { + baseUnit = ParseStub ("a = b};", false); + expr = baseUnit.GetNodeAt (location.Line, location.Column - 1); + } + Print (baseUnit); + if (expr == null) + return null; var member = Unit.GetNodeAt (memberLocation); var member2 = baseUnit.GetNodeAt (memberLocation); if (member != null && member2 != null) {