Browse Source

[Completion] Fixed completion bug.

newNRvisualizers
Mike Krüger 13 years ago
parent
commit
584eb443b7
  1. 12
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 18
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  3. 23
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionAccessibleTests.cs

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

@ -1113,12 +1113,16 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
location.Line, location.Line,
location.Column + 2, location.Column + 2,
n => n is Expression || n is AstType || n is NamespaceDeclaration n => n is Expression || n is AstType || n is NamespaceDeclaration
); );
rr = ResolveExpression(node); rr = ResolveExpression(node);
} }
// namespace name case // namespace name case
if (node is NamespaceDeclaration) var ns = node as NamespaceDeclaration;
return null; if (ns != null) {
var last = ns.Identifiers.LastOrDefault ();
if (last != null && location < last.EndLocation)
return null;
}
if (node is Identifier && node.Parent is ForeachStatement) { if (node is Identifier && node.Parent is ForeachStatement) {
var foreachStmt = (ForeachStatement)node.Parent; var foreachStmt = (ForeachStatement)node.Parent;
foreach (var possibleName in GenerateNameProposals (foreachStmt.VariableType)) { foreach (var possibleName in GenerateNameProposals (foreachStmt.VariableType)) {
@ -1228,7 +1232,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return t.GetAllBaseTypeDefinitions().Any(bt => bt.Equals(attribute)) ? t : null; return t.GetAllBaseTypeDefinitions().Any(bt => bt.Equals(attribute)) ? t : null;
}; };
} }
if (node != null || state.CurrentTypeDefinition != null || isInGlobalDelegate) { if (node != null && !(node is NamespaceDeclaration) || state.CurrentTypeDefinition != null || isInGlobalDelegate) {
AddTypesAndNamespaces(wrapper, state, node, typePred); AddTypesAndNamespaces(wrapper, state, node, typePred);
wrapper.Result.Add(factory.CreateLiteralCompletionData("global")); wrapper.Result.Add(factory.CreateLiteralCompletionData("global"));

18
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -405,15 +405,17 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode insertPos = null; AstNode insertPos = null;
while (memberName != null) { while (memberName != null) {
Identifier newIdent = Identifier.Create (memberName.Name, Convert (memberName.Location)); Identifier newIdent = Identifier.Create (memberName.Name, Convert (memberName.Location));
namespaceDecl.InsertChildBefore (insertPos, newIdent, Roles.Identifier); // HACK for a parser 'bug' - sometimes it generates "<invalid>" identifiers in namespace names (on certain bugs in the input file)
insertPos = newIdent; if (newIdent.Name != "<invalid>") {
namespaceDecl.InsertChildBefore (insertPos, newIdent, Roles.Identifier);
if (!memberName.DotLocation.IsNull) { insertPos = newIdent;
var dotToken = new CSharpTokenNode (Convert (memberName.DotLocation), Roles.Dot);
namespaceDecl.InsertChildBefore (insertPos, dotToken, Roles.Dot); if (!memberName.DotLocation.IsNull) {
insertPos = dotToken; var dotToken = new CSharpTokenNode (Convert (memberName.DotLocation), Roles.Dot);
namespaceDecl.InsertChildBefore (insertPos, dotToken, Roles.Dot);
insertPos = dotToken;
}
} }
memberName = memberName.Left; memberName = memberName.Left;
} }
} }

23
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionAccessibleTests.cs

@ -1421,5 +1421,28 @@ namespace ConsoleApplication2
Assert.AreEqual (1, count); Assert.AreEqual (1, count);
}); });
} }
/// <summary>
/// Bug 5648 - Types are displayed even when cannot be used
/// </summary>
[Test()]
public void TestBug5648 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"
using System;
namespace N
{
$e$
}
", provider => {
Assert.IsNotNull (provider.Find ("enum"), "'enum' not found.");
Assert.IsNotNull (provider.Find ("namespace"), "'namespace' not found.");
Assert.IsNotNull (provider.Find ("public"), "'public' not found.");
Assert.IsNull (provider.Find ("CharEnumerator"), "'CharEnumerator' found.");
Assert.IsNull (provider.Find ("Console"), "'Console' found.");
});
}
} }
} }
Loading…
Cancel
Save