Browse Source

Fixed code completion bug.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
d8d65fc9d9
  1. 15
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 35
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

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

@ -2062,13 +2062,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2062,13 +2062,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
} else {
memberLocation = location;
}
var baseUnit = ParseStub ("");
var baseUnit = ParseStub ("a");
var tmpUnit = baseUnit;
AstNode expr = baseUnit.GetNodeAt<IdentifierExpression> (location.Line, location.Column - 1);
if (expr == null)
expr = baseUnit.GetNodeAt<Attribute> (location.Line, location.Column - 1);
if (expr == null)
AstNode expr = baseUnit.GetNodeAt (location, n => n is IdentifierExpression || n is MemberReferenceExpression);
if (expr == null) {
expr = baseUnit.GetNodeAt<AstType> (location.Line, location.Column - 1);
if (expr is AstType && expr.Parent is Attribute)
expr = expr.Parent;
}
// try insertStatement
if (expr == null && baseUnit.GetNodeAt<EmptyStatement> (location.Line, location.Column) != null) {
@ -2139,7 +2140,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2139,7 +2140,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (expr != null)
expr = baseUnit.GetNodeAt<Expression> (location.Line, location.Column) ?? expr;
if (expr == null)
expr = baseUnit.GetNodeAt<Attribute> (location.Line, location.Column);
expr = baseUnit.GetNodeAt<AstType> (location.Line, location.Column);
if (expr is AstType && expr.Parent is Attribute)
expr = expr.Parent;
}
if (expr == null)
return null;

35
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -4545,5 +4545,40 @@ class Test @@ -4545,5 +4545,40 @@ class Test
Assert.IsNotNull (provider.Find ("Value2"), "field 'Value2' not found.");
}
/// <summary>
/// Bug 3581 - [New Resolver] No code completion on Attributes
/// </summary>
[Test()]
public void TestBug3581 ()
{
CompletionDataList provider = CreateProvider (
@"using System;
namespace Foobar
{
class Intent
{
public static int Foo = 0;
public static int Bar = 1;
}
class MyAttribute : Attribute
{
public int[] Categories;
}
[MyAttribute(Categories = new [] { $I$ })]
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine (ddsd);
}
}
}
");
Assert.IsNotNull (provider.Find ("Intent"), "'Intent' not found.");
}
}
}

Loading…
Cancel
Save