提交 0a6697e3 编写于 作者: C CyrusNajmabadi

Handle this.<name> expressions.

上级 976fc437
......@@ -7310,6 +7310,37 @@ public Class()
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateVariable)]
public async Task TestPlaceFieldBasedOnSurroundingStatements2()
{
await TestInRegularAndScriptAsync(
@"class Class
{
private int foo;
private int quux;
public Class()
{
this.foo = 0;
this.[|bar|] = 1;
this.quux = 2;
}
}",
@"class Class
{
private int foo;
private int bar;
private int quux;
public Class()
{
this.foo = 0;
this.bar = 1;
this.quux = 2;
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateVariable)]
public async Task TestPlacePropertyBasedOnSurroundingStatements()
{
......
......@@ -277,14 +277,15 @@ internal bool CanGenerateLocal()
// Also, because users often like to keep members/assignments in the same order
// we can pick a good place for the new member based on the surrounding assignments.
var syntaxFacts = document.Document.GetLanguageService<ISyntaxFactsService>();
var simpleName = this.SimpleNameOpt;
var simpleName = this.SimpleNameOrMemberAccessExpressionOpt;
if (syntaxFacts.IsLeftSideOfAssignment(simpleName))
{
var assignmentStatement = simpleName.Ancestors().FirstOrDefault(syntaxFacts.IsSimpleAssignmentStatement);
if (assignmentStatement != null)
{
syntaxFacts.GetPartsOfAssignmentStatement(assignmentStatement, out var left, out var right);
syntaxFacts.GetPartsOfAssignmentStatement(
assignmentStatement, out var left, out var right);
if (left == simpleName)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册