Skip to content

Move to namespace UI and Implementation#34223

Merged
ryzngard merged 53 commits intodotnet:masterfrom
ryzngard:feature/move_to_namespace_features/ui
Apr 4, 2019
Merged

Move to namespace UI and Implementation#34223
ryzngard merged 53 commits intodotnet:masterfrom
ryzngard:feature/move_to_namespace_features/ui

Conversation

@ryzngard
Copy link
Copy Markdown
Contributor

@ryzngard ryzngard commented Mar 18, 2019

This implements 'MoveToNamespace' as a feature. See this comment for context on the design.

Note: all screenshots have a black bar for the XAML debugger since they are taken from running under the VS debugger. That will not be in the final UI.

Case 1: Move and individual type

Class "Bar" is being targetted. Suggestion is provided as a code action. Ctrl + . or clicking on the indicator in the left margin will invoke the menu shown. Selecting the option will show the dialog

Code Action Suggestion

MoveTypeContextMenu

Dialog

MoveTypeDialog

Case 2: Move all items in a namespace scope

Namespace "Foo.Bar.Namespace" is being targetted. Suggestion is provided as a code action. Ctrl + . or clicking on the indicator in the left margin will invoke the menu shown. Selecting the option will show the dialog. Expected result would be that all items in the current scope (indicated by the opening { and closing }) would be moved. Currently the only class that would be moved is Bar. Implementation is incomplete, so finished result is not shown.

Code Action Suggestion

MoveItemsContextMenu

Dialog

MoveItemsDialog

General Dialog Usage

Dialog AutoComplete

DialogAutoComplete

Uses default autocomplete for the control with a list of namespaces from the project.

Dialog Dropdown

DialogDropdown

Same list as autocomplete in dropdown form.

Dialog Error State

DialogError

Used to indicate that the current namespace suggestion is not valid.

New Name Information

DialogNewNamespace

Used to indicate that the user is creating a namespace that doesn't currently exist. This is allowed, but may be harder to spot with a dropdown/autocomplete control. Purely informational

Andrew Hall (METAL) added 13 commits March 18, 2019 14:45
Move to namespace allows a user to move all symbols in a context
to a different namespace, whether it's a new one or existing. This is
different from renaming a namespace as not all symbols in the namespace
are moved, only ones within the current document.

It relies on the IChangeNamespaceService implementation to do the heavy
lifting. Since the current implementation only supports C#, this new
feature will as well.

After this is checked in, when a user has the cursor inside a namespace
declaration that has no nested namespace declarations within it, a code
fix will be suggested to pop up a dialog and help the user choose a new
namespace.
@ryzngard ryzngard marked this pull request as ready for review March 19, 2019 00:16
@ryzngard ryzngard requested review from a team as code owners March 19, 2019 00:16
@ryzngard ryzngard requested a review from dpoeschl March 19, 2019 00:16
@sharwell
Copy link
Copy Markdown
Contributor

Integration test hit this:

Event Time (UTC): 3/20/2019 1:13:51 AM
Event ID: 1025
Data: Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: System.NullReferenceException: Object reference not set to an instance of an object.

   at Microsoft.CodeAnalysis.CSharp.MoveToNamespace.CSharpMoveToNamespaceService.GetNamespaceName(NamespaceDeclarationSyntax syntax)

   at Microsoft.CodeAnalysis.CSharp.MoveToNamespace.CSharpMoveToNamespaceService.GetNamespaceName(TypeDeclarationSyntax syntax)

   at Microsoft.CodeAnalysis.MoveToNamespace.AbstractMoveToNamespaceService`3.<AnalyzeTypeAtPositionAsync>d__5.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()

   at Microsoft.CodeAnalysis.MoveToNamespace.AbstractMoveToNamespaceService`3.<GetCodeActionsAsync>d__4.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()

   at Microsoft.CodeAnalysis.MoveToNamespace.MoveToNamespaceCodeActionProvider.<ComputeRefactoringsAsync>d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()

   at Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.<GetRefactoringFromProviderAsync>d__8.MoveNext()
Stack:
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, System.Action`1<System.Exception>)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception)
   at Microsoft.VisualStudio.IntegrationTest.Setup.TestExtensionErrorHandler.HandleError(System.Object, System.Exception)
   at Microsoft.VisualStudio.IntegrationTest.Setup.TestExtensionManager+ExtensionManager.HandleException(System.Object, System.Exception)
   at Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService+<GetRefactoringFromProviderAsync>d__8.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon ByRef)
   at Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(Microsoft.CodeAnalysis.Document, Microsoft.CodeAnalysis.Text.TextSpan, Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringProvider, Microsoft.CodeAnalysis.Extensions.IExtensionManager, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService+<HasRefactoringsAsync>d__6.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon ByRef)
   at Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.HasRefactoringsAsync(Microsoft.CodeAnalysis.Document, Microsoft.CodeAnalysis.Text.TextSpan, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionsSourceProvider+SuggestedActionsSource+<TryGetRefactoringSuggestedActionCategoryAsync>d__42.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon ByRef)
   at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionsSourceProvider+SuggestedActionsSource.TryGetRefactoringSuggestedActionCategoryAsync(Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionsSourceProvider, Microsoft.CodeAnalysis.Document, System.Nullable`1<Microsoft.CodeAnalysis.Text.TextSpan>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionsSourceProvider+SuggestedActionsSource+<>c__DisplayClass49_2.<GetSuggestedActionCategoriesAsync>b__1()
   at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.Tasks.Task.ExecutionContextCallback(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

@ryzngard
Copy link
Copy Markdown
Contributor Author

Integration test hit this:

Thanks, this is a bug on my end. I need to handle cases where a type isn't enclosed in a namespace declaration. Glad the integration tests are running :) thanks @sharwell !

@dpoeschl
Copy link
Copy Markdown
Contributor

dpoeschl commented Apr 2, 2019

@ryzngard I filed #34685 to track the IVsRefactorNotify scenario.

Copy link
Copy Markdown
Contributor

@dpoeschl dpoeschl left a comment

Choose a reason for hiding this comment

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

Done with this pass.


Example:

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.

was this intentional?

Copy link
Copy Markdown
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@dpoeschl dpoeschl left a comment

Choose a reason for hiding this comment

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

👍

@ryzngard ryzngard merged commit 7c2d7a9 into dotnet:master Apr 4, 2019
@vatsalyaagrawal
Copy link
Copy Markdown
Contributor

👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants