dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.
https://josefpihrt.github.io/docs/roslynator
Other
3.04k stars 251 forks source link

New refactoring rename namespace by folder structure #50

Open martinsura opened 7 years ago

martinsura commented 7 years ago

Hello,

Nice extensions. Is here any plan to support rename namespace by folder structure?

Thanks

josefpihrt commented 7 years ago

This requires access to "default namespace" property, which is not currently supported.

See https://github.com/dotnet/roslyn/issues/3798.

kieronlanning commented 7 years ago

+1

Can you work it out based on the folder structure, up to the point of hitting a project file, like a .csproj in the case of C#?

It would unblock this feature, and for 90% of cases I'm pretty sure that would work.

josefpihrt commented 7 years ago

@kieronlanning I'm afraid don't understand your proposal. How do you want to obtain default namespace?

kieronlanning commented 7 years ago

The default namespace is usually the project name, or in the .csproj it has RootNamespace in a PropertyGroup if it's been overridden.

josefpihrt commented 7 years ago

That would mean to read and parse csproj file every time a refactoring is computed (every time before it is displayed in the context menu).

felixhirt commented 5 years ago

According to dotnet/roslyn#31253, it seems the roslyn team is working on this very refactoring (a basic version of it works in VisualStudio 2019 RC). It does not seem as if they are providing a warning for it though (at least not at the moment).

Would it be possible to add an analyzer to Roslynator that provides the warning (If i understand correctly, the default namespace is now exposed in the project system dotnet/roslyn#30998)? The refactoring can be used from Rosyln itself i guess.

felixhirt commented 5 years ago

Uh, im afraid i was a bit too eager. It seems there is still no way to get the project context from a code analyzer. But maybe the roslyn team will turn the refactoring into an analyzer