From 23da7447b458d68adfc9ec412f3049d4293221ae Mon Sep 17 00:00:00 2001 From: MisaJovanovic Date: Sun, 9 Sep 2018 23:35:02 +0200 Subject: [PATCH 1/3] Fix missing signatures --- .../Signatures/SignatureHelpService.cs | 4 ++- .../SignatureHelpFacts.cs | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Signatures/SignatureHelpService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Signatures/SignatureHelpService.cs index d6dec7191d..03a8137d57 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Signatures/SignatureHelpService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Signatures/SignatureHelpService.cs @@ -69,7 +69,9 @@ public async Task 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)); } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs index ea49ceb02f..5ab09035a8 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs @@ -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); + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task TypeOfContextMethod(string filename) + { + const string source = +@"class A +{ + static void M() + { + string a = typeof(A).GetMembers($$); + } +}"; + var actual = await GetSignatureHelp(filename, source); + Assert.NotEmpty(actual.Signatures); + } + [Fact] public async Task OverloadedExtensionMethods1() { From 1b18f7fdfe855f7633925f0d6289d4feff31cbbe Mon Sep 17 00:00:00 2001 From: MisaJovanovic Date: Mon, 10 Sep 2018 02:31:06 +0200 Subject: [PATCH 2/3] this makes more sense --- .../SignatureHelpFacts.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs index 5ab09035a8..4384506c9e 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs @@ -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); @@ -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) { @@ -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) { @@ -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() { @@ -760,7 +760,7 @@ public async Task TypeOfContextMethod(string filename) { static void M() { - string a = typeof(A).GetMembers($$); + var members = typeof(A).GetMembers($$); } }"; var actual = await GetSignatureHelp(filename, source); @@ -916,7 +916,7 @@ public static void Main() var flag = Compare($$); } ///Checks if object is tagged with the tag. - /// The game object. + /// The game object. /// Name of the tag. /// Returns true if object is tagged with tag. public static bool Compare(GameObject gameObject, string tagName) @@ -948,7 +948,7 @@ public static void Main() var flag = Compare($$); } ///Checks if object is tagged with the tag. - /// The game object. + /// The game object. /// Name of the tag.It has the default value as null /// Returns true if object is tagged with tag. public static bool Compare(GameObject gameObject, string tagName = null) @@ -977,7 +977,7 @@ public static void Main() var flag = Compare($$); } ///Checks if object is tagged with the tag. - /// The game object. + /// The game object. /// Name of the tag. /// Returns true if object is tagged with tag. public static bool Compare(GameObject gameObject, string tagName) From f8ea62294d11ac07798f9c0d0973ba7317ff91a7 Mon Sep 17 00:00:00 2001 From: MisaJovanovic Date: Thu, 27 Sep 2018 22:36:55 +0200 Subject: [PATCH 3/3] enhance tests --- tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs index 4384506c9e..9d00fcdd57 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs @@ -747,7 +747,7 @@ static void M() } }"; var actual = await GetSignatureHelp(filename, source); - Assert.NotEmpty(actual.Signatures); + Assert.Contains(actual.Signatures, signature => signature.Name == "ToString" && signature.Parameters.Count() == 0); } [Theory] @@ -764,7 +764,7 @@ static void M() } }"; var actual = await GetSignatureHelp(filename, source); - Assert.NotEmpty(actual.Signatures); + Assert.Contains(actual.Signatures, signature => signature.Name == "GetMembers" && signature.Parameters.Count() == 0); } [Fact] @@ -793,7 +793,7 @@ public static void Main() Assert.Single(actual.Signatures); var signature = actual.Signatures.ElementAt(0); - Assert.Equal("void string.MyMethod(int number)",signature.Label); + Assert.Equal("void string.MyMethod(int number)", signature.Label); Assert.Single(signature.Parameters); Assert.Equal("number", signature.Parameters.ElementAt(0).Name); }