-
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
Move Type to Namespace refactoring #30896
Comments
I've been looking into how we can do this, and I think we have a few options: Option 1 Invocation would be refactor suggestion on left side when cursor is in a type declaration. On invocation, would bring up a dialog that allows selection of any "top level" declaration (directly inside a namespace, not nested in another type) to be selected. A new namespace name is given via a textbox, and resulting code is moved within the same file but encapsulated in the new namespace. If a namespace in the file would be left empty, it is removed. Option 2 Option 3 I believe Option 1 is the current best target, but we should discuss. |
Having to specify the target namespace manually, without anything to help out, seems pretty arduous. |
I'm not opposed to having something like autocomplete for helping decide a namespace if it's already existing. That seems like a good value add. We still want to allow a new namespace to be specified as well. |
Yeah. Intellisense both supports suggesting namespaces when in a namespace name. And we have precidence for intellisense inside a text-box (i.e. the debugger windows). |
Current ProposalTwo ways to move types to a new namespace.
Both will be refactor suggesions on namespace declaration (1) or type declaration (2). All references will be updated same as "sync to namespace" feature. UIUI will be the same for both cases, since all that will be needed is a new namespace. If the namespace is the same as the original, no action will be taken. A single input field with fully qualified namespaces from the current project as suggestions. ExamplesFor each example, the All types within a declarationExample 1Beforenamespace $$Some.Existing.Name
{
class Foo { }
class Bar { }
} Afternamespace Chunky.Bacon
{
class Foo { }
class Bar { }
} Example 2Before$$namespace Some.Existing.Name
{
interface IBar { }
class Bar : IBar { }
} Afternamespace Chunky.Bacon
{
interface IBar { }
class Bar : IBar { }
} Example 3BeforeFoo.cs namespace Some.Existing.Name$$
{
class Foo { }
} Bar.cs namespace Some.Existing.Name
{
class Bar : Foo { }
} AfterFoo.cs namespace Chunky.Bacon
{
class Foo { }
} Bar.cs using Chunky.Bacon;
namespace Some.Existing.Name
{
class Bar : Foo { }
} Move individual typeOnly apply to top level types in a namespace; no nested types. Move to own namespace declaration scope in same file if more than one declaration in the current scope. Namespaces will be split to accomodate the new declaration. Example 1Beforenamespace Some.Existing.Name
{
class $$Baz { }
class Foo { }
class Bar { }
} Afternamespace Chunky.Bacon
{
class Baz { }
}
namespace Some.Existing.Name
{
class Foo { }
class Bar { }
} Example 2Beforenamespace Some.Existing.Name
{
class Baz { }
$$class Foo { }
class Bar { }
} Afternamespace Some.Existing.Name
{
class Baz { }
}
namespace Chunky.Bacon
{
class Foo { }
}
namespace Some.Existing.Name
{
class Bar { }
} Example 3Beforenamespace Some.Existing.Name
{
class Baz { }
class Foo { }
class Bar$$ { }
} Afternamespace Some.Existing.Name
{
class Baz { }
class Foo { }
}
namespace Chunky.Bacon
{
class Bar { }
} Future ImprovementsShould this be a shortcut and added to More places this gets suggested as a refactoring? Current scope may not have enough visibility. Select items from list to move multiple at same time. Consolidation of move refactorings provided. Sync file name or location to match new namespace |
@ryzngard I understand the dialog being the same (mostly), but can the lightbulb entry text be distinct for the two cases? The behavior difference being the caret position (between type and namespace declarations) makes sense to me intuitively, but I'd still want the text the be clear about what's going to happen, especially if one or more types in a namespace declaration are scrolled offscreen (
I personally don't think this is necessary/desirable.
I assume you were using the |
I'll update the examples to use
I think that's a great way to help distinguish intent. It also reaffirms the context of the action. The suggestions seem to make sense, but I'll consider it more.
@dpoeschl interesting... why is that? Movement as a whole is personally something I do a lot as I write code. It also works in almost any context. Maybe if we consolidate our move operations then that would make sense to promote to top level. |
@ryzngard Yes. I'd prefer we figure out what we want this suite of operations to look like before assigning a keyboard shortcut to one specific action that we might later want to take back for a broader operation of some sort. EDIT: And then have another conversation about the merits of a shortcut, at least partially informed by telemetry etc. |
The work for this is done. Any further feedback should be filed as new issues |
Moved from link
This should replace Namespace declarations in the original files and make sure that usages are updated accordingly.
The text was updated successfully, but these errors were encountered: