Skip to content

Fix matchnamespacetofolder analyzer/codefix#55424

Merged
ryzngard merged 3 commits intodotnet:mainfrom
ryzngard:issues/sync_namespace_root
Aug 5, 2021
Merged

Fix matchnamespacetofolder analyzer/codefix#55424
ryzngard merged 3 commits intodotnet:mainfrom
ryzngard:issues/sync_namespace_root

Conversation

@ryzngard
Copy link
Copy Markdown
Contributor

@ryzngard ryzngard commented Aug 5, 2021

Fix issues where the namespace for documents at the root would be incorrect.

Fixes: #54757

@ryzngard ryzngard requested a review from a team as a code owner August 5, 2021 00:29
@ghost ghost added the Area-IDE label Aug 5, 2021
@ryzngard ryzngard requested a review from JoeRobich August 5, 2021 00:29
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

Does this fix the exception System.InvalidOperationException : This Workspace does not support changing a document's Folders.?

I'd be interested to know what was causing it. I just saw it's fixed in VS layer.

var targetNamespace = namespaceFromFolders == null
? null
: ConcatNamespace(defaultNamespace, namespaceFromFolders);
var targetNamespace = PathMetadataUtilities.TryBuildNamespaceFromFolders(document.Folders, syntaxFacts, defaultNamespace);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this change behavior? The code refactoring didn't have any issues. So I don't get why a change is needed here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

// 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The analyzer has already correctly calculated the correct namespace. See the diagnostic message:

image

Can't we just pass it in the properties bag and avoid recalculating it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'CSharpChangeNamespaceToMatchFolderCodeFixProvider' encountered an error and has been disabled

5 participants