Skip to content
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 @@ -102,6 +102,32 @@ record Class
}
""", new TestParameters(TestOptions.RegularPreview));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76813")]
public Task TestSingleGetterFromField_CommentBeforeField()
=> TestInRegularAndScript1Async(
"""
class Class
{
// Comment to preserve
[|int i|];

int P
{
get
{
return i;
}
}
}
""",
"""
class Class
{
// Comment to preserve
int P { get; }
}
""");

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28511")]
public Task TestNullable1()
=> TestMissingInRegularAndScriptAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,18 @@ private async Task<Solution> ProcessResultWorkerAsync(
// it. As long as something is above it, we keep the separation. However, if the
// property becomes the first member in the type, the separation is now inappropriate
// because there's nothing to actually separate it from.
var fieldDocumentSyntaxFacts = fieldDocument.GetRequiredLanguageService<ISyntaxFactsService>();
if (fieldDocument == propertyDocument)
{
var syntaxFacts = fieldDocument.GetRequiredLanguageService<ISyntaxFactsService>();
var bannerService = fieldDocument.GetRequiredLanguageService<IFileBannerFactsService>();
if (WillRemoveFirstFieldInTypeDirectlyAboveProperty(syntaxFacts, propertyDeclaration, nodeToRemove) &&
if (WillRemoveFirstFieldInTypeDirectlyAboveProperty(fieldDocumentSyntaxFacts, propertyDeclaration, nodeToRemove) &&
bannerService.GetLeadingBlankLines(nodeToRemove).Length == 0)
{
updatedProperty = bannerService.GetNodeWithoutLeadingBlankLines(updatedProperty);
}
}

var syntaxRemoveOptions = CreateSyntaxRemoveOptions(nodeToRemove);
var syntaxRemoveOptions = CreateSyntaxRemoveOptions(fieldDocumentSyntaxFacts, nodeToRemove);
if (fieldDocument == propertyDocument)
{
// Same file. Have to do this in a slightly complicated fashion.
Expand Down Expand Up @@ -326,15 +326,13 @@ private async Task<Solution> ProcessResultWorkerAsync(
return (fieldSymbol, propertySymbol);
}

private static SyntaxRemoveOptions CreateSyntaxRemoveOptions(SyntaxNode nodeToRemove)
private static SyntaxRemoveOptions CreateSyntaxRemoveOptions(
ISyntaxFacts syntaxFacts, SyntaxNode nodeToRemove)
{
var syntaxRemoveOptions = SyntaxGenerator.DefaultRemoveOptions;
var hasDirective = nodeToRemove.GetLeadingTrivia().Any(t => t.IsDirective);

if (hasDirective)
{
if (nodeToRemove.GetLeadingTrivia().Any(t => t.IsDirective || syntaxFacts.IsRegularComment(t)))
syntaxRemoveOptions |= SyntaxRemoveOptions.KeepLeadingTrivia;
}

return syntaxRemoveOptions;
}
Expand Down
Loading