Browse Source

Improve ResolveAtLocation.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
9859dce24f
  1. 18
      ICSharpCode.NRefactory.CSharp/Resolver/ResolveAtLocation.cs
  2. 15
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolveAtLocationTests.cs

18
ICSharpCode.NRefactory.CSharp/Resolver/ResolveAtLocation.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// </summary>
public static class ResolveAtLocation
{
public static ResolveResult Resolve(ICompilation compilation, CSharpParsedFile parsedFile, CompilationUnit cu, TextLocation location,
public static ResolveResult Resolve(ICompilation compilation, CSharpParsedFile parsedFile, CompilationUnit cu, TextLocation location,
CancellationToken cancellationToken = default(CancellationToken))
{
AstNode node;
@ -47,7 +47,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -47,7 +47,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (node is Identifier) {
node = node.Parent;
} else if (node.NodeType == NodeType.Token) {
if (node.Parent is ConstructorInitializer) {
if (node.Parent is IndexerExpression || node.Parent is ConstructorInitializer) {
// There's no other place where one could hover to see the indexer's tooltip,
// so we need to resolve it when hovering over the '[' or ']'.
// For constructor initializer, the same applies to the 'base'/'this' token.
node = node.Parent;
} else {
return null;
@ -56,6 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -56,6 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
// don't resolve arbitrary nodes - we don't want to show tooltips for everything
return null;
}
} else {
// It's a resolvable node.
// However, we usually don't want to show the tooltip everywhere
// For example, hovering with the mouse over an empty line between two methods causes
// node==TypeDeclaration, but we don't want to show any tooltip.
if (!node.GetChildByRole(AstNode.Roles.Identifier).IsNull) {
// We'll suppress the tooltip for resolvable nodes if there is an identifier that
// could be hovered over instead:
return null;
}
}
if (node == null)
return null;

15
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolveAtLocationTests.cs

@ -32,6 +32,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -32,6 +32,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
Assert.IsNull(ResolveAtLocation("usi$ng System;"));
}
[Test]
public void InsideClassBody()
{
Assert.IsNull(ResolveAtLocation("class Test { $ }"));
}
[Test]
public void UsingDeclarationNamespace()
{
@ -117,5 +123,14 @@ class A { public A() : ba$se() {} }"); @@ -117,5 +123,14 @@ class A { public A() : ba$se() {} }");
var rr = ResolveAtLocation<MemberResolveResult>("public class A { event EventHandler Test, Te$st2; }");
Assert.AreEqual("Test2", rr.Member.Name);
}
[Test]
public void Indexer()
{
var rr = ResolveAtLocation<CSharpInvocationResolveResult>(
"using System.Collections.Generic;" +
"public class A { int M(List<int> a) { return a$[1]; } }");
Assert.AreEqual(EntityType.Indexer, rr.Member.EntityType);
}
}
}

Loading…
Cancel
Save