-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[WIP] Sync namespace and folder refactoring (C#) #30156
Conversation
f12377c
to
a2a97e9
Compare
Can you provide a little more info? Just a high level overview of the design, and maybe any particularly interesting points. For example, does this make your namespaces match your folder structure? Or your folder structure match your namespaces? (or both?). How do you deal with assembly-names/default-namespace names. How would this work in something like Roslyn. For example, we have a ton of 'Feature' assembly code with namespace like "namespace Microsoft.CodeAnalysis.SomeFeature". However, we don't create namespace for "Microsoft" or "CodeAnalysis" because of how excessive it would be. Is that handled at all? |
src/EditorFeatures/CSharpTest/CodeActions/SyncNamespace/CSharpSyncNamespaceTestsBase.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/CodeActions/SyncNamespace/CSharpSyncNamespaceTestsBase.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
Outdated
Show resolved
Hide resolved
...CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); | ||
|
||
// Bail if multiple namespaces are declared in the document (including nested declarations) | ||
if (root.DescendantNodes().OfType<TNamespaceDeclarationSyntax>().Count() > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely worth calling out in the original description.
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
...ortable/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceCodeRefactoringProvider.State.cs
Outdated
Show resolved
Hide resolved
Done with pass. Note:
There was a bunch of feedback left in the PR that was never addressed. I would definitely appreciate it if it can be. The feedback is not given lightly :) Outside of nits, it's often there because with my best attempt of understanding the code there were things that were not clear. And that can be a big problem with code maintenance. If someone has to come 6-12 months from now to fixup something, they may often fix things at the wrong level or in hte wrong way if it's not super clear to them what's going on. Thanks! |
@CyrusNajmabadi Yes, let's keep using this PR until you signed off. I will rebase & retarget then.
For some of your unaddressed comments at least I probably just missed them, I will try to look from the beginning again to make sure. Also it'd be great if you can ping on those to bring them to my attention. Thanks! :) |
@CyrusNajmabadi I think I have responded to all your comments. As mentioned, things related to moving language specific logic to attract layer will be done later. Please take a another look and let me know if I missed anything. |
Great! I'm doing async-completion and pull-up first (since i was asked first) :) Will try to review this afterrwards. |
src/Features/CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceService.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceService.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceService.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/CodeRefactorings/SyncNamespace/CSharpSyncNamespaceService.cs
Outdated
Show resolved
Hide resolved
...ble/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceService.ChangeNamespaceCodeAction.cs
Outdated
Show resolved
Hide resolved
...ble/CodeRefactorings/SyncNamespace/AbstractSyncNamespaceService.ChangeNamespaceCodeAction.cs
Outdated
Show resolved
Hide resolved
Overall, things are looking quite good. Has there been verification with cases inside roslyn itself (say, at the workspace layer)? We havea bunch of types that are in the wrong namespace. I'd really like to know how well this works in a real-world project. |
@CyrusNajmabadi Comments addressed. Please take another look. Thanks! |
@CyrusNajmabadi I just tried the "change namespace" action on Roslyn 2.0 snapshot, it seems at least for some of the less prevalent types I tried (e.g. |
@heejaechang I have made a few more iterations of changes since you last reviewed, do you mind to take another quick look please? I have rebased the PR to target Preview 2 branch here, so you don't have to look at all the existing comments :) |
|
@CyrusNajmabadi Do you have any concerns that's still blocking? I will profile this and make perf improvement later, given that I will be continue working on this service and implement some related code refactorings. |
if (nameRef.Parent is NameMemberCrefSyntax crefName && crefName.Parent is QualifiedCrefSyntax qualifiedCref) | ||
{ | ||
// This is the case where the reference is a qualified name in `cref`. | ||
// for example, `<see cref="Foo.Baz.Bar"/>` and `<see cref="SomeAlias::Foo.Baz.Bar"/>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider test where this references a method as well off off an alias qualified name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add in the rebased PR
I think i'm good at thsi point. Any additional concerns ca come through later PRs. Awesome job! |
@CyrusNajmabadi Thanks for the code review! i will compile all remaining issues and file a bug for them |
[Marked as WIP avoid accidental merge, this change should target master. A new PR is created for that but I'd like to keep this around for review purpose]
Implement #14341
As mentioned in dotnet/vblang#351, this will not be provided for VB.
Remaining issues/work that will be addressed in separate PRs
Just to give you an idea, here's how current implementation works with some basic scenarios. The root namespace for the sample project is
ClassLibrary4