Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sync namespace analyzer #49990

Merged
67 commits merged into from
Feb 9, 2021
Merged

Conversation

ryzngard
Copy link
Contributor

@ryzngard ryzngard commented Dec 15, 2020

Sync namespace analyzer will warn and provide code fixes for when namespaces do not match the folder structure. It should follow the same logic as https://docs.microsoft.com/en-us/visualstudio/ide/reference/sync-namespace-and-folder-name?view=vs-2019 but will allow users to configure warning severity and have CI integration.

@ryzngard ryzngard marked this pull request as ready for review December 17, 2020 22:05
@ryzngard ryzngard requested a review from a team as a code owner December 17, 2020 22:05
Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

// TODO : can this cause a loop? This condition was used by the service before,
// but now could possibly add an Error severity as an analyzer
var isCurrentNamespaceInvalid = namespaceDeclaration.Name
.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check for DefaultSeverity + id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like an odd check. i'm not sure what it's really trying to ask

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this is needed. Even if the namespace is invalid, is it practical to suggest the correct name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping on this. Intent was to check that the namespace was valid before suggesting to fix. Thoughts on what the right behavior should be?

Co-authored-by: Manish Vasani <[email protected]>
Co-authored-by: David Wengier <[email protected]>
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looking good. some things i found a bit confusing though and would like clarity on.

where TNamespaceSyntax : SyntaxNode
{
private static readonly LocalizableResourceString s_localizableTitle = new(
nameof(AnalyzersResources.Namespace_does_not_match_folder_structure), AnalyzersResources.ResourceManager, typeof(AnalyzersResources));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent properly.

nameof(AnalyzersResources.Namespace_does_not_match_folder_structure), AnalyzersResources.ResourceManager, typeof(AnalyzersResources));

private static readonly LocalizableResourceString s_localizableInsideMessage = new(
nameof(AnalyzersResources.Namespace_0_does_not_match_folder_structure_expected_1), AnalyzersResources.ResourceManager, typeof(AnalyzersResources));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider inlining these two statics. up to you, but it's waht we do in lots of other places.


private static readonly SymbolDisplayFormat s_namespaceDisplayFormat = SymbolDisplayFormat
.FullyQualifiedFormat
.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: place statics above constructor.

return;
}

if (context.Node is TNamespaceSyntax namespaceDecl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my preference would be a hard-cast here as this shouldn't be possible to fail.

/// on a sequential level instead of batch fixing and merging the changes. This prevents
/// collissions that the batch fixer won't handle correctly but is slower.
/// </summary>
internal abstract partial class AbstractChangeNamespaceToMatchFolderCodeFixProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name is so much better. t hanks.

public MyCodeAction(string title, Func<CancellationToken, Task<Solution>> createChangedSolution)
: base(title, createChangedSolution)
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approval

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants