Skip to content

Commit

Permalink
Merge pull request #2244 from JoeRobich/support-implicit-creation
Browse files Browse the repository at this point in the history
Support signature help for implicit object creation
  • Loading branch information
JoeRobich authored Oct 12, 2021
2 parents 22524f9 + fc2ad7a commit 2790ac6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
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

0 comments on commit 2790ac6

Please sign in to comment.