-
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
Rename API handles refactor notify #41126
Conversation
This allows IVsRefactorNotify to be handled automatically when calling Solution.TryApplyChanges
4abad93
to
17c380e
Compare
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.
Overall the direction here looks great. A few general thoughts:
- It'd be nice if the various code action tests just tested the existence of the annotation, and we had a single test that tested that the Workspace does the right thing when it encouters it; this keeps all the individual features from having to set up the refactor notify stuff directly.
- We may need to refactor the stuff into TryApplyChanges better -- right now there's duplicate code between TestWorkspace and VisualStudioWorkspace. It also looks like there's a bug in the VisualStudioWorkspace variant that might prevent it from working, so that's worrisome -- the unit tests may pass but it'll fail in the actual product.
- We might be able to clean up more in Rename tracking too -- that also is directly invoking IRefactorNotify which might now be unnecessary. It actually might mean we're firing the events twice now.
- Ditto for ContainedLanguageCodeSupport.cs which isn't here: that's also firing events directly. At this point with this PR I'd guess you can just search on IRefactorNotifySymbol and only see the workspace stuff directly interacting with it -- anybody else still firing it manually is probably a duplicate invocation.
src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs
Outdated
Show resolved
Hide resolved
@@ -1217,17 +1231,42 @@ public async Task TestRefactorNotify() | |||
var testParameters = new TestParameters(options: options.ClassNamesArePascalCase); | |||
|
|||
using var workspace = CreateWorkspaceFromOptions(markup, testParameters); | |||
|
|||
var refactorNotify = workspace.GetService<IRefactorNotifyService>() as TestRefactorNotify; |
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.
At this point, is there some way to make these tests not have to grovel with IRefactorNotifyService and just have a helper that asserts the rename annotation was added? And have a standalone test that does all the refactor notify stuff directly?
@@ -21,7 +22,7 @@ public class MoveToNamespaceTests : AbstractMoveToNamespaceTests | |||
{ | |||
private static readonly IExportProviderFactory ExportProviderFactory = | |||
ExportProviderCache.GetOrCreateExportProviderFactory( | |||
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestMoveToNamespaceOptionsService))); | |||
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestMoveToNamespaceOptionsService)).WithPart(typeof(TestRefactorNotify))); |
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.
Why? What happens if it's not there?
var currentSemanticModel = await oldDocument.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); | ||
|
||
var oldSymbol = ResolveSymbol(annotation, currentSemanticModel.Compilation); | ||
var newSymbol = newSemanticModel.GetDeclaredSymbol(node); |
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.
GetDeclaredSymbol could return null, why did it let you pass that to changedSymbols.Add?
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.
It can, but shouldn't in this case right? Assuming we're always annotating something that declares a symbol (which is the useful point of this). Maybe just add a contract throw?
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.
I'm more worried why the compiler didn't yell at you. Is this a bug in nullable somewhere?
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.
hmm... the extension method is annotated as return a non-null value. Potentially by design but not desired...
SemanticModel.GetDeclaredSymbolForNode
might be annotated wrong?
src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs
Show resolved
Hide resolved
Tagging @dpoeschl to also look at this, since he has background in both rename tracking and IRefactorNotifyService; there might be some other nice cleanups that happen too. I could also imagine things breaking too: if the rename tracking is now running through the common code, that might also trigger the dismissal of the session in some way that might interact poorly. |
Agreed. I'll work on a test helper for this. I think having a mock refactornotify test is worthwhile still, but more general use would be to check annotation.
hmm... maybe good chance to add more integration tests?
Same as above :)
I'll dig into these implementations. Having multiple IRefactorNotifySymbol is not necessarily bad, but they shouldn't all be calling into the VS layer. We should have 1 per endpoint that needs to be called. |
@ryzngard What would you like to do with this PR? |
This change makes it so that the rename API we surface pubilicly marks symbol definitions with an annotation.
An editor workspace implementation can use those annotations as hints to what has been refactored, and handle these changes if needed. For the case of VS, that includes calling IVsRefactorNotify on TryApplyChanges