You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is basically a continuation of #7929. The use case here is I want to be able to check if the code formatting satisfies the specific formatting settings and provide warning + code fix if it doesn't. Formatter.GetFormattedTextChanges seems like the way to go here, but unfortunately it's part of Microsoft.CodeAnalysis.Workspaces, which can't be used in an analyzer without producing tons of warnings on build.
As discussed in the issue I've mentioned, I'd like to suggest refactoring out a version of this method that doesn't need Workspace, operates only on SyntaxNode and an instance of formatting settings and resides in an assembly that can be used safely both during build and in VS.
The text was updated successfully, but these errors were encountered:
var oraginalText = context.Tree.GetText(cancellationToken);
var formatedText = context.Tree.GetRoot(cancellationToken).NormalizeWhitespace().GetText();
var changes = formatedText.GetTextChanges(oraginalText);
foreach (var change in changes)
{
var diagnostic = Diagnostic.Create(Rule, context.Tree.GetLocation(change.Span));
context.ReportDiagnostic(diagnostic);
}
This is basically a continuation of #7929. The use case here is I want to be able to check if the code formatting satisfies the specific formatting settings and provide warning + code fix if it doesn't.
Formatter.GetFormattedTextChanges
seems like the way to go here, but unfortunately it's part ofMicrosoft.CodeAnalysis.Workspaces
, which can't be used in an analyzer without producing tons of warnings on build.As discussed in the issue I've mentioned, I'd like to suggest refactoring out a version of this method that doesn't need
Workspace
, operates only onSyntaxNode
and an instance of formatting settings and resides in an assembly that can be used safely both during build and in VS.The text was updated successfully, but these errors were encountered: