Browse Source

Fixed for variable initializer name context.

newNRvisualizers
mike 14 years ago
parent
commit
afbf9c9624
  1. 24
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 36
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  3. 13
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/NameContextTests.cs

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

@ -511,6 +511,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -511,6 +511,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return null;
}
if (identifierStart != null && identifierStart.Node is Identifier) {
// May happen in variable names
return controlSpace ? DefaultControlSpaceItems(identifierStart) : null;
}
if (identifierStart != null && identifierStart.Node is VariableInitializer && location <= ((VariableInitializer)identifierStart.Node).NameToken.EndLocation) {
return controlSpace ? HandleAccessorContext() ?? DefaultControlSpaceItems(identifierStart) : null;
}
@ -2307,14 +2312,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2307,14 +2312,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
ExpressionResult GetExpressionAtCursor()
{
// TextLocation memberLocation;
// if (currentMember != null) {
// memberLocation = currentMember.Region.Begin;
// } else if (currentType != null) {
// memberLocation = currentType.Region.Begin;
// } else {
// memberLocation = location;
// }
// TextLocation memberLocation;
// if (currentMember != null) {
// memberLocation = currentMember.Region.Begin;
// } else if (currentType != null) {
// memberLocation = currentType.Region.Begin;
// } else {
// memberLocation = location;
// }
var baseUnit = ParseStub("a");
var tmpUnit = baseUnit;
@ -2322,7 +2327,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2322,7 +2327,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (expr == null) {
expr = baseUnit.GetNodeAt<AstType>(location.Line, location.Column - 1);
}
if (expr == null)
expr = baseUnit.GetNodeAt<Identifier>(location.Line, location.Column - 1);
// try insertStatement
if (expr == null && baseUnit.GetNodeAt<EmptyStatement>(location.Line, location.Column) != null) {
tmpUnit = baseUnit = ParseStub("a();", false);

36
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -415,9 +415,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -415,9 +415,9 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
wrapper.Append (';');
}
protected CompilationUnit ParseStub (string continuation, bool appendSemicolon = true, string afterContinuation = null)
protected CompilationUnit ParseStub(string continuation, bool appendSemicolon = true, string afterContinuation = null)
{
var mt = GetMemberTextToCaret ();
var mt = GetMemberTextToCaret();
if (mt == null) {
return null;
}
@ -429,7 +429,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -429,7 +429,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var wrapper = new StringBuilder ();
bool wrapInClass = memberLocation != new TextLocation (1, 1);
if (wrapInClass) {
var nodeAtLocation = Unit.GetNodeAt (memberLocation, n => n is TypeDeclaration || n is NamespaceDeclaration);
var nodeAtLocation = Unit.GetNodeAt(memberLocation, n => n is TypeDeclaration || n is NamespaceDeclaration);
if (nodeAtLocation != null) {
foreach (var n in nodeAtLocation.AncestorsAndSelf) {
if (memberLocation == n.StartLocation) {
@ -438,25 +438,25 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -438,25 +438,25 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (n is TypeDeclaration) {
var t = (TypeDeclaration)n;
switch (t.ClassType) {
case ClassType.Class:
wrapper.Append ("class");
break;
case ClassType.Struct:
wrapper.Append ("struct");
break;
case ClassType.Interface:
wrapper.Append ("interface");
break;
case ClassType.Enum:
wrapper.Append ("enum");
break;
case ClassType.Class:
wrapper.Append("class");
break;
case ClassType.Struct:
wrapper.Append("struct");
break;
case ClassType.Interface:
wrapper.Append("interface");
break;
case ClassType.Enum:
wrapper.Append("enum");
break;
}
wrapper.Append (" " + t.Name + " {");
wrapper.AppendLine ();
wrapper.Append(" " + t.Name + " {");
wrapper.AppendLine();
closingBrackets++;
generatedLines++;
} else {
Console.WriteLine (n);
Console.WriteLine(n);
}
}
}

13
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/NameContextTests.cs

@ -122,6 +122,19 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion @@ -122,6 +122,19 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
Assert.IsTrue (provider == null || provider.Count == 0, "provider should be empty.");
}
[Test()]
public void TestForLoopLocalVariableName ()
{
var provider = CodeCompletionBugTests.CreateProvider (@"class MyClass {
void Test()
{
$for (int f$
}
}");
Assert.IsTrue (provider == null || provider.Count == 0, "provider should be empty.");
}
[Test()]
public void TestCatchExceptionName ()
{

Loading…
Cancel
Save