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

Fix missing signatures for some cases #1290

Merged
merged 9 commits into from
Nov 2, 2018
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public async Task<SignatureHelpResponse> Handle(SignatureHelpRequest request)
var throughExpression = ((MemberAccessExpressionSyntax)invocation.Receiver).Expression;
throughSymbol = invocation.SemanticModel.GetSpeculativeSymbolInfo(invocation.Position, throughExpression, SpeculativeBindingOption.BindAsExpression).Symbol;
throughType = invocation.SemanticModel.GetSpeculativeTypeInfo(invocation.Position, throughExpression, SpeculativeBindingOption.BindAsTypeOrNamespace).Type;
var includeInstance = throughSymbol != null && !(throughSymbol is ITypeSymbol);
var includeInstance = (throughSymbol != null && !(throughSymbol is ITypeSymbol)) ||
throughExpression is LiteralExpressionSyntax ||
throughExpression is TypeOfExpressionSyntax;
var includeStatic = (throughSymbol is INamedTypeSymbol) || throughType != null;
methodGroup = methodGroup.Where(m => (m.IsStatic && includeStatic) || (!m.IsStatic && includeInstance));
}
Expand Down
60 changes: 47 additions & 13 deletions tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,21 @@ public async Task AttributeCtorSingleParam(string filename)
const string source =
@"using System;
[MyTest($$)]
public class TestClass
public class TestClass
{
public static void Main()
{
}
}
public class MyTestAttribute : Attribute
public class MyTestAttribute : Attribute
{
public MyTestAttribute(int value)
{
}
}";
var actual = await GetSignatureHelp(filename, source);
var actual = await GetSignatureHelp(filename, source);
Assert.Equal(0, actual.ActiveParameter);

var signature = actual.Signatures.ElementAt(0);
Assert.Single(signature.Parameters);
Assert.Equal("value", signature.Parameters.ElementAt(0).Name);
Expand All @@ -206,13 +206,13 @@ public async Task AttributeCtorTestParameterLabels(string filename)
const string source =
@"using System;
[MyTest($$)]
public class TestClass
public class TestClass
{
public static void Main()
{
}
}
public class MyTestAttribute : Attribute
public class MyTestAttribute : Attribute
{
public MyTestAttribute(int value1,double value2)
{
Expand All @@ -238,13 +238,13 @@ public async Task AttributeCtorActiveParamBasedOnComma(string filename)
const string source =
@"using System;
[MyTest(2,$$)]
public class TestClass
public class TestClass
{
public static void Main()
{
}
}
public class MyTestAttribute : Attribute
public class MyTestAttribute : Attribute
{
public MyTestAttribute(int value1,double value2)
{
Expand All @@ -263,13 +263,13 @@ public async Task AttributeCtorNoParam(string filename)
const string source =
@"using System;
[MyTest($$)]
public class TestClass
public class TestClass
{
public static void Main()
{
}
}
public class MyTestAttribute : Attribute
public class MyTestAttribute : Attribute
{
public MyTestAttribute()
{
Expand Down Expand Up @@ -733,6 +733,40 @@ static void M1(int a,int b,int c,int d) { }
Assert.Equal(4, actual.Signatures.Count());
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task LiteralContextMethod(string filename)
{
const string source =
@"class A
{
static void M()
{
string three = 3.ToString($$);
}
}";
var actual = await GetSignatureHelp(filename, source);
Assert.NotEmpty(actual.Signatures);
Copy link
Member

Choose a reason for hiding this comment

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

It would be great if this could also assert that one of the intended signatures exists.

Copy link
Member

Choose a reason for hiding this comment

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

This way we can avoid potential signatures being removed when they shouldn't have been.

}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task TypeOfContextMethod(string filename)
{
const string source =
@"class A
{
static void M()
{
var members = typeof(A).GetMembers($$);
}
}";
var actual = await GetSignatureHelp(filename, source);
Assert.NotEmpty(actual.Signatures);
Copy link
Member

Choose a reason for hiding this comment

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

It would be great if this could also assert that one of the intended signatures exists.

}

[Fact]
public async Task OverloadedExtensionMethods1()
{
Expand Down Expand Up @@ -882,7 +916,7 @@ public static void Main()
var flag = Compare($$);
}
///<summary>Checks if object is tagged with the tag.</summary>
/// <param name=""gameObject"">The game object.</param>
/// <param name=""gameObject"">The game object.</param>
/// <param name=""tagName"">Name of the tag.</param>
/// <returns>Returns <c> true</c> if object is tagged with tag.</returns>
public static bool Compare(GameObject gameObject, string tagName)
Expand Down Expand Up @@ -914,7 +948,7 @@ public static void Main()
var flag = Compare($$);
}
///<summary>Checks if object is tagged with the tag.</summary>
/// <param name=""gameObject"">The game object.</param>
/// <param name=""gameObject"">The game object.</param>
/// <param name=""tagName"">Name of the tag.It has the default value as <c>null</c></param>
/// <returns>Returns <c> true</c> if object is tagged with tag.</returns>
public static bool Compare(GameObject gameObject, string tagName = null)
Expand Down Expand Up @@ -943,7 +977,7 @@ public static void Main()
var flag = Compare($$);
}
///<summary>Checks if object is tagged with the tag.</summary>
/// <param name=""gameObject"">The game object.</param>
/// <param name=""gameObject"">The game object.</param>
/// <param name=""tagName"">Name of the tag.</param>
/// <returns>Returns <c>true</c> if object is tagged with tag.</returns>
public static bool Compare(GameObject gameObject, string tagName)
Expand Down