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
if (!(char.IsLetter (completionChar) || completionChar == '_') && (!controlSpace || identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) { if (!(char.IsLetter (completionChar) || completionChar == '_') && (!controlSpace || identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) {
return controlSpace ? HandleAccessorContext () ?? DefaultControlSpaceItems (identifierStart) : null; return controlSpace ? HandleAccessorContext () ?? DefaultControlSpaceItems (identifierStart) : null;
} }
char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : ';'; char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : ';';
char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' '; char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' ';
const string allowedChars = ";,[](){}+-*/%^?:&|~!<>="; const string allowedChars = ";,[](){}+-*/%^?:&|~!<>=";
@ -470,6 +469,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
} }
CSharpResolver csResolver; CSharpResolver csResolver;
AstNode n = identifierStart.Item2; AstNode n = identifierStart.Item2;
if (n != null && n.Parent is AnonymousTypeCreateExpression) {
AutoSelect = false;
}
// Handle foreach (type name _ // Handle foreach (type name _
if (n is IdentifierExpression) { if (n is IdentifierExpression) {
var prev = n.GetPrevNode () as ForeachStatement; var prev = n.GetPrevNode () as ForeachStatement;
@ -2019,10 +2023,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
// try expression in anonymous type "new { sample = x$" case // try expression in anonymous type "new { sample = x$" case
if (expr == null) { if (expr == null) {
baseUnit = ParseStub ("a };", false); baseUnit = ParseStub ("a", false);
Print (baseUnit);
expr = baseUnit.GetNodeAt<AnonymousTypeCreateExpression> (location.Line, location.Column); expr = baseUnit.GetNodeAt<AnonymousTypeCreateExpression> (location.Line, location.Column);
if (expr != null) if (expr != null)
expr = baseUnit.GetNodeAt<Expression> (location.Line, location.Column); expr = baseUnit.GetNodeAt<Expression> (location.Line, location.Column) ?? expr;
} }
if (expr == null) if (expr == null)

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

@ -402,12 +402,13 @@ class A
{ {
public static void Main (string[] args) 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()] [Test()]
@ -427,6 +428,7 @@ class A
"); ");
Assert.IsNotNull(provider); // <--- here 0 item in the completion list 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("a"), "'a' not found");
Assert.IsNotNull(provider.Find("new"), "'new' not found"); Assert.IsNotNull(provider.Find("new"), "'new' not found");
Assert.IsNotNull(provider.Find("args"), "'args' not found"); Assert.IsNotNull(provider.Find("args"), "'args' not found");

Loading…
Cancel
Save