Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense not showing methods from the Base class in Signature Help #1030

Merged
merged 17 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
Expand Down Expand Up @@ -59,7 +60,7 @@ public async Task<SignatureHelpResponse> Handle(SignatureHelpRequest request)
foreach (var invocation in invocations)
{
var types = invocation.ArgumentTypes;
foreach (var methodOverload in GetMethodOverloads(invocation.SemanticModel, invocation.Receiver))
foreach (var methodOverload in invocation.SemanticModel.GetMemberGroup(invocation.Receiver).OfType<IMethodSymbol>())
{
var signature = BuildSignature(methodOverload);
signaturesSet.Add(signature);
Expand Down Expand Up @@ -115,27 +116,6 @@ private async Task<InvocationContext> GetInvocation(Document document, Request r
return null;
}

private IEnumerable<IMethodSymbol> GetMethodOverloads(SemanticModel semanticModel, SyntaxNode node)
{
ISymbol symbol = null;
var symbolInfo = semanticModel.GetSymbolInfo(node);
if (symbolInfo.Symbol != null)
{
symbol = symbolInfo.Symbol;
}
else if (!symbolInfo.CandidateSymbols.IsEmpty)
{
symbol = symbolInfo.CandidateSymbols.First();
}

if (symbol == null || symbol.ContainingType == null)
{
return new IMethodSymbol[] { };
}

return symbol.ContainingType.GetMembers(symbol.Name).OfType<IMethodSymbol>();
}

private int InvocationScore(IMethodSymbol symbol, IEnumerable<TypeInfo> types)
{
var parameters = GetParameters(symbol);
Expand All @@ -162,7 +142,7 @@ private int InvocationScore(IMethodSymbol symbol, IEnumerable<TypeInfo> types)
}
}

return score;
return score;
}

private static SignatureHelpItem BuildSignature(IMethodSymbol symbol)
Expand Down
58 changes: 57 additions & 1 deletion tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,69 @@ public Program(Program p, int n)
{
}
}";

var actual = await GetSignatureHelp(source);
Assert.Equal(3, actual.Signatures.Count());
Assert.Equal(1, actual.ActiveParameter);
Assert.Contains("ctor2", actual.Signatures.ElementAt(actual.ActiveSignature).Documentation);
}

[Fact]
public async Task SignatureHelpForOverloadedMethodsInheritance()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a case for methods with the same name that shouldn't be accessible? Eg:

    class Program
    {
        static void Main(string[] args)
        {
        }

        private void Foo() { }
    }

    class G : Program
    {
        protected void Foo() { }
    }

{
const string source =
@"public class MyBase
{
public void MyMethod(int a) { }
public void MyMethod(int a, int b) { }
}

public class Class1 : MyBase
{
public void MyMethod(int a, int b, int c) { }
public void MyMethod(int a, int b, int c, int d) { }
}

public class Class2
{
public void foo()
{
Class1 c1 = new Class1();
c1.MyMethod($$);
}

}";
var actual = await GetSignatureHelp(source);
Assert.Equal(4, actual.Signatures.Count());
}

[Fact]
public async Task SignatureHelpForOverloadedInaccesibleMethods()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test to verify behavior if there's an extension method with the same name?

{
const string source =
@"public class MyBase
{
private void MyMethod(int a) { }
}

public class Class1 : MyBase
{
public void MyMethod(int a, int b, int c) { }
protected void MyMethod(int a, int b, int c, int d) { }
}

public class Class2
{
public void foo()
{
Class1 c1 = new Class1();
c1.MyMethod($$);
}

}";
var actual = await GetSignatureHelp(source);
Assert.Single(actual.Signatures);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we verify which signature we got?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should.Added that.

}

[Fact]
public async Task SkipReceiverOfExtensionMethods()
{
Expand Down