Fix matchnamespacetofolder analyzer/codefix#55424
Merged
ryzngard merged 3 commits intodotnet:mainfrom Aug 5, 2021
Merged
Conversation
davidwengier
approved these changes
Aug 5, 2021
JoeRobich
approved these changes
Aug 5, 2021
Youssef1313
reviewed
Aug 5, 2021
Youssef1313
reviewed
Aug 5, 2021
| var targetNamespace = namespaceFromFolders == null | ||
| ? null | ||
| : ConcatNamespace(defaultNamespace, namespaceFromFolders); | ||
| var targetNamespace = PathMetadataUtilities.TryBuildNamespaceFromFolders(document.Folders, syntaxFacts, defaultNamespace); |
Member
There was a problem hiding this comment.
Does this change behavior? The code refactoring didn't have any issues. So I don't get why a change is needed here
Contributor
Author
There was a problem hiding this comment.
This just cleans up a little since I changed TryBuildNamespaceFromFolders. No change in behavior here, but does ensure that analyzer and refactoring calculate the target the same.
Youssef1313
reviewed
Aug 5, 2021
| // to rewrite or move the complex logic. RenameDocumentAsync is designed to behave the same | ||
| // as the intent of this analyzer/codefix pair. | ||
| var targetFolders = PathMetadataUtilities.BuildFoldersFromNamespace(targetNamespace); | ||
| var targetFolders = PathMetadataUtilities.BuildFoldersFromNamespace(targetNamespace, document.Project.DefaultNamespace); |
Member
Contributor
Author
There was a problem hiding this comment.
We already are. The fix here is to avoid duplicating the default namespace. BuildFoldersFromNamespace will build relative folders, but if it doesn't know the default/root namespace it will do it incorrectly.
See how targetNamespace gets assigned. It comes from the analyzer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fix issues where the namespace for documents at the root would be incorrect.
Fixes: #54757