Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 69182ed

Browse files
authored
Merge pull request #30 from episerver/user/shsh/add-view-location-comments
add view location comments
2 parents 2ef3492 + 8d89d03 commit 69182ed

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/EpiSourceUpdater/EpiPartialControllerCodeFixProvider.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ private static async Task<Document> ReplaceNameAndReturnParameterAsync(Document
9090
private static async Task<Document> ReplacePartialViewMethodAsync(Document document, IdentifierNameSyntax identifierNameSyntax, CancellationToken cancellationToken)
9191
{
9292
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
93-
94-
var updatedName = identifierNameSyntax.WithIdentifier(SyntaxFactory.Identifier("View"));
93+
var comment = SyntaxFactory.Comment($"//The default convention for views and viewcomponent is '/Views/Shared/Components/ComponentName/Default.cshtml'");
94+
var leadingTrivia = GetAncestorsTrivia(identifierNameSyntax);
95+
var updatedName = identifierNameSyntax.WithIdentifier(SyntaxFactory.Identifier(SyntaxTriviaList.Create(SyntaxFactory.CarriageReturnLineFeed).AddRange(leadingTrivia).Add(comment).Add(SyntaxFactory.CarriageReturnLineFeed).AddRange(leadingTrivia), "View", SyntaxTriviaList.Empty));
9596
var newRoot = root!.ReplaceNode(identifierNameSyntax, updatedName);
96-
9797
// Return document with transformed tree.
9898
return document.WithSyntaxRoot(newRoot);
9999
}
100+
101+
private static SyntaxTriviaList GetAncestorsTrivia(IdentifierNameSyntax identifierNameSyntax) =>
102+
identifierNameSyntax.Ancestors().Where(a => a.HasLeadingTrivia).FirstOrDefault()?.GetLeadingTrivia()?? SyntaxTriviaList.Empty;
100103
}
101104
}

src/EpiSourceUpdater/EpiPartialRouterCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private async Task<Document> HandlePartialRouteRegistration(Document document, I
148148
//The registration is done somewhere where we do not have access to IServiceCollection, add a comment on how registration should be done
149149
var parameterType = getPartialRouterArgument is ObjectCreationExpressionSyntax objectCreationExpression ? objectCreationExpression.Type.ToString() : "CustomPartialRouter";
150150
var comment = SyntaxFactory.Comment($"//Partial router should be registered in ioc container like 'services.AddSingleton<IPartialRouter, {parameterType}>()'");
151-
statements = statements.Insert(index, statement.WithLeadingTrivia(statement.GetLeadingTrivia().Add(comment).Add(SyntaxFactory.CarriageReturnLineFeed)));
151+
statements = statements.Insert(index, statement.WithLeadingTrivia(statement.GetLeadingTrivia().Add(comment).Add(SyntaxFactory.CarriageReturnLineFeed).AddRange(statement.GetLeadingTrivia())));
152152
}
153153

154154
var newCodeBlock = currentCodeBlock.WithStatements(statements);

0 commit comments

Comments
 (0)