From fb374aaa12daceffed8f846bb1229e06529f9210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Mon, 31 Oct 2011 10:20:50 +0100 Subject: [PATCH] Fixed unit test. --- .../Completion/CSharpCompletionEngine.cs | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index 7e59765c14..29ba9e2dde 100644 --- a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -372,27 +372,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } var contextList = new CompletionDataWrapper (this); - if (identifierStart == null) { - var unit = ParseStub ("get; }", false); - var node = unit.GetNodeAt (location, cn => !(cn is CSharpTokenNode)); - if (node is Accessor) - node = node.Parent; - if (node is PropertyDeclaration) { - contextList.AddCustom ("get"); - contextList.AddCustom ("set"); - AddKeywords (contextList, accessorModifierKeywords); - } else if (node is CustomEventDeclaration) { - contextList.AddCustom ("add"); - contextList.AddCustom ("remove"); - } else { - AddContextCompletion (contextList, GetState (), null); - } - - return contextList.Result; - } if (!(char.IsLetter (completionChar) || completionChar == '_') && (identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) - return controlSpace ? DefaultControlSpaceItems () : null; + 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 = ";,[(){}+-*/%^?:&|~!<>="; @@ -408,6 +390,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion if (!char.IsLetterOrDigit (last) && last != '_') return null; } + + if (identifierStart == null) + return HandleAccessorContext () ?? DefaultControlSpaceItems (); + CSharpResolver csResolver; AstNode n = identifierStart.Item2; if (n is ArrayInitializerExpression) { @@ -427,7 +413,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } return null; } - if (n != null/* && !(identifierStart.Item2 is TypeDeclaration)*/) { csResolver = new CSharpResolver (ctx, System.Threading.CancellationToken.None); var nodes = new List (); @@ -544,6 +529,27 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return false; } + IEnumerable HandleAccessorContext () + { + var unit = ParseStub ("get; }", false); + var node = unit.GetNodeAt (location, cn => !(cn is CSharpTokenNode)); + if (node is Accessor) + node = node.Parent; + var contextList = new CompletionDataWrapper (this); + if (node is PropertyDeclaration) { + contextList.AddCustom ("get"); + contextList.AddCustom ("set"); + AddKeywords (contextList, accessorModifierKeywords); + } else if (node is CustomEventDeclaration) { + contextList.AddCustom ("add"); + contextList.AddCustom ("remove"); + } else { + return null; + } + + return contextList.Result; + } + IEnumerable DefaultControlSpaceItems () { var wrapper = new CompletionDataWrapper (this); @@ -562,8 +568,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion node = Unit.GetNodeAt (location); rr = ResolveExpression (CSharpParsedFile, node, Unit); } - - AddContextCompletion (wrapper, rr != null ? rr.Item2 : GetState (), node); + AddContextCompletion (wrapper, rr != null && (node is Expression) ? rr.Item2 : GetState (), node); return wrapper.Result; }