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

Move type to "correct" file #13

Open
sharwell opened this issue Nov 17, 2014 · 10 comments
Open

Move type to "correct" file #13

sharwell opened this issue Nov 17, 2014 · 10 comments

Comments

@sharwell
Copy link
Member

I propose a refactoring analyzer which is capable of handling two situations.

  1. A single top-level type is defined in a file which does not match the name of the class

    This refactoring would rename the file to match the metadata name of the type it contains. For non-generic types, this is just the simple name of the type. For generic types, this is the simple name for the type followed by a ` and then the generic arity.

  2. Multiple top-level types are defined in a file

    For the type, if any, which matches the name of the file, no refactoring is proposed. For other types defined in the file, the refactoring would move the type to its own file based on the name of the type.

It would also be possible to create a diagnostic for these situations, which is applicable to projects where the situation should be proactively avoided.

@tugberkugurlu
Copy link

yes, yes, yes! I want this!

enjoy

@tugberkugurlu
Copy link

A few questions and thoughts I have for this:

  • Is it possible to pop up a UI during refactoring phase to make the user choose a location inside the solution?
  • It also needs handle using statement refactorings if the file is moved under a different namespace.

@sharwell
Copy link
Member Author

For this refactoring, it would make sense to place the file in the same folder as the source file it was extracted from. A separate refactoring could be implemented for moving a file to a new folder based on the namespace of the type it contains.

@johannesegger
Copy link

I know this feature from ReSharper, I love it, and that's why I would like to take that one. Creating and transfering a repository seems to be not that easy, so I suggest you create one under DotNetAnalysers.

Should this be a diagnostic or a refactoring?
I personally would prefer a diagnostic as I think type name and file name should be identical, but maybe that is controversial?

I thought of naming it either TypeToFile[Diagnostic|Refactoring], TypeNameToFileName[Diagnostic|Refactoring], ExtractTypeToFile[Diagnostic|Refactoring] or ExtractType[Diagnostic|Refactoring], but I would hope that you or anyone else has some better ideas, because none of the above exactly matches your description.

@sharwell
Copy link
Member Author

It's pretty easy to move; that was just the first time i tried to move someone else's repository. I wouldn't let that stop you, especially since I'm not available to create a new one here until next week.

@johannesegger
Copy link

Ahh ok, I've never done that before. It doesn't stop me, no worries :-), I always have my local repo.

@sharwell
Copy link
Member Author

Cool. I look forward to seeing it! 👍

@johannesegger
Copy link

Ok, so this project is currently hosted here and of course everyone is invited to contribute.

@paulomorgado
Copy link

@eggapauli, I believe you forgot to remove the MakeUppercaseAsync method.

@johannesegger
Copy link

Oh you are right, thanks. I used this as a template, because I'm new to the Roslyn API.

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

No branches or pull requests

4 participants