Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed last failing code completion unit test.

  • Loading branch information...
commit 59ce505e14039f93d83a792e78252081abb496b0 1 parent bc4ca21
@mkrueger mkrueger authored
View
30 ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
@@ -388,7 +388,6 @@ IEnumerable<ICompletionData> MagicKeyCompletion (char completionChar, bool contr
if (!char.IsLetterOrDigit (last) && last != '_')
return null;
}
-
if (identifierStart == null)
return null;
@@ -532,9 +531,22 @@ bool IsInLinqContext (int offset)
IEnumerable<ICompletionData> DefaultControlSpaceItems ()
{
var wrapper = new CompletionDataWrapper (this);
+ while (offset > 0 && char.IsWhiteSpace (document.GetCharAt (offset))) {
+ offset--;
+ }
+ location = document.GetLocation (offset);
+ var xp = GetExpressionAtCursor ();
- var node = Unit.GetNodeAt (location);
- var rr = ResolveExpression (CSharpParsedFile, node, Unit);
+ AstNode node;
+ Tuple<ResolveResult, CSharpResolver> rr;
+ if (xp != null) {
+ node = xp.Item2;
+ rr = ResolveExpression (xp.Item1, node, xp.Item3);
+ } else {
+ node = Unit.GetNodeAt (location);
+ rr = ResolveExpression (CSharpParsedFile, node, Unit);
+ }
+
AddContextCompletion (wrapper, rr != null ? rr.Item2 : GetState (), node);
return wrapper.Result;
@@ -1571,6 +1583,18 @@ IEnumerable<ICompletionData> CreateCaseCompletionData (TextLocation location)
// try statement
if (expr == null) {
expr = tmpUnit.GetNodeAt<SwitchStatement> (location.Line, location.Column - 1);
+ baseUnit = tmpUnit;
+ }
+
+ if (expr == null) {
+ var forStmt = tmpUnit.GetNodeAt<ForStatement> (location.Line, location.Column - 3);
+ expr = forStmt;
+ if (forStmt != null && forStmt.EmbeddedStatement.IsNull) {
+ var id = new IdentifierExpression ("stub");
+ forStmt.EmbeddedStatement = new BlockStatement () { Statements = { new ExpressionStatement (id) }};
+ expr = id;
+ }
+ baseUnit = tmpUnit;
}
if (expr == null)
View
18 ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
@@ -3218,6 +3218,24 @@ public static void Main (string[] args)
}
/// <summary>
+ /// Bug 675956 - Completion in for loops is broken
+ /// </summary>
+ [Test()]
+ public void TestBug675956Case2 ()
+ {
+ CompletionDataList provider = CreateProvider (
+@"class Test
+{
+ public static void Main (string[] args)
+ {
+ $for (int i = 0; i$
+ }
+}
+");
+ Assert.IsNotNull (provider.Find ("i"), "variable 'i' not found.");
+ }
+
+ /// <summary>
/// Bug 676311 - auto completion too few proposals in fluent API (Moq)
/// </summary>
[Test()]
Please sign in to comment.
Something went wrong with that request. Please try again.