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

Support signature help for implicit object creation #2244

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -119,7 +119,7 @@ private async Task<InvocationContext> GetInvocation(Document document, Request r
return new InvocationContext(semanticModel, position, invocation.Expression, invocation.ArgumentList, invocation.IsInStaticContext());
}

if (node is ObjectCreationExpressionSyntax objectCreation && objectCreation.ArgumentList.Span.Contains(position))
if (node is BaseObjectCreationExpressionSyntax objectCreation && objectCreation.ArgumentList.Span.Contains(position))
{
var semanticModel = await document.GetSemanticModelAsync();
return new InvocationContext(semanticModel, position, objectCreation, objectCreation.ArgumentList, objectCreation.IsInStaticContext());
Expand Down
60 changes: 58 additions & 2 deletions tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,62 @@ public Program(Program p)
Assert.Equal(3, actual.Signatures.Count());
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task TestForImplicitCreationConstructorHelp(string filename)
{
const string source =
@"class Program
{
public static void Main()
{
Program program = new($$)
}
public Program()
{
}
public Program(bool b)
{
}
public Program(Program p)
{
}
}";

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

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task TestForImplicitCreationCtorWithOverloads(string filename)
{
const string source =
@"class Program
{
public static void Main()
{
Program program = new(true, 12$$3)
}
public Program()
{
}
/// ctor2
public Program(bool b, int n)
{
}
public Program(Program p, int n)
{
}
}";
var actual = await GetSignatureHelp(filename, source);
Assert.Equal(3, actual.Signatures.Count());
Assert.Equal(1, actual.ActiveParameter);
Assert.Contains("ctor2", actual.Signatures.ElementAt(actual.ActiveSignature).Documentation);
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
Expand Down Expand Up @@ -606,7 +662,7 @@ void M1(int a)
}
}";
var actual = await GetSignatureHelp(filename, source);
Assert.Equal(2,actual.Signatures.Count());
Assert.Equal(2, actual.Signatures.Count());
}

[Theory]
Expand Down Expand Up @@ -706,7 +762,7 @@ public void M1(int a,int b,int c,int d) { }
Assert.Equal(2, actual.Signatures.Count());
var signatures = actual.Signatures.OrderBy(sig => sig.Parameters.Count());
Assert.Single(signatures.ElementAt(0).Parameters);
Assert.Equal(3,signatures.ElementAt(1).Parameters.Count());
Assert.Equal(3, signatures.ElementAt(1).Parameters.Count());
}

[Theory]
Expand Down