Browse Source

Improved anonymous type context.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
a126210ec5
  1. 11
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 6
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs

11
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -440,7 +440,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -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 @@ -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 @@ -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<AnonymousTypeCreateExpression> (location.Line, location.Column);
if (expr != null)
expr = baseUnit.GetNodeAt<Expression> (location.Line, location.Column);
expr = baseUnit.GetNodeAt<Expression> (location.Line, location.Column) ?? expr;
}
if (expr == null)

6
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs

@ -402,12 +402,13 @@ class A @@ -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 @@ -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");

Loading…
Cancel
Save