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

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

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

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

@ -1421,5 +1421,28 @@ namespace ConsoleApplication2 @@ -1421,5 +1421,28 @@ namespace ConsoleApplication2
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