提交 47ddfef9 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #16269 from rchande/fix14084

Show object creation completion in method calls before assignments. F…
......@@ -452,6 +452,54 @@ public async Task BeforeAttributeParsedAsImplicitArray()
}
";
await VerifyItemExistsAsync(markup, "Program");
}
[WorkItem(14084, "https://github.com/dotnet/roslyn/issues/14084")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InMethodCallBeforeAssignment1()
{
var markup =
@"namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
object o;
string s;
Test(new $$
o = s;
}
static void Test(TimeSpan t, TimeSpan t2) { }
}
}
";
await VerifyItemExistsAsync(markup, "TimeSpan");
}
[WorkItem(14084, "https://github.com/dotnet/roslyn/issues/14084")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InMethodCallBeforeAssignment2()
{
var markup =
@"namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
object o;
string s;
Test(new TimeSpan(), new $$
o = s;
}
static void Test(TimeSpan t, TimeSpan t2) { }
}
}
";
await VerifyItemExistsAsync(markup, "TimeSpan");
}
}
}
......@@ -368,8 +368,17 @@ private IEnumerable<TypeInferenceInfo> InferTypeInObjectCreationExpression(Objec
//
// In both these cases, we simply back up before the 'new' if it follows an equals
// and start the inference again.
//
// Analogously, but in a method call:
// Test(new $$
// o = s
// or:
// Test(1, new $$
// o = s
// The new is part of the assignment to o but the user is really trying to
// add a parameter to the method call.
if (previousToken.Kind() == SyntaxKind.NewKeyword &&
previousToken.GetPreviousToken().Kind() == SyntaxKind.EqualsToken)
previousToken.GetPreviousToken().IsKind(SyntaxKind.EqualsToken, SyntaxKind.OpenParenToken, SyntaxKind.CommaToken))
{
return InferTypes(previousToken.SpanStart);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册