diff --git a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index f0aa50cc08..294d251372 100644 --- a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -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 (location.Line, location.Column - 1); - if (expr == null) - expr = baseUnit.GetNodeAt (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 (location.Line, location.Column - 1); + if (expr is AstType && expr.Parent is Attribute) + expr = expr.Parent; + } // try insertStatement if (expr == null && baseUnit.GetNodeAt (location.Line, location.Column) != null) { @@ -2139,7 +2140,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion if (expr != null) expr = baseUnit.GetNodeAt (location.Line, location.Column) ?? expr; if (expr == null) - expr = baseUnit.GetNodeAt (location.Line, location.Column); + expr = baseUnit.GetNodeAt (location.Line, location.Column); + if (expr is AstType && expr.Parent is Attribute) + expr = expr.Parent; } if (expr == null) return null; diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs index 53119bbbf7..93ea7656aa 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs @@ -4545,5 +4545,40 @@ class Test Assert.IsNotNull (provider.Find ("Value2"), "field 'Value2' not found."); } + /// + /// Bug 3581 - [New Resolver] No code completion on Attributes + /// + [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."); + } } }