-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Change Method Signature: change definition #25144
Comments
After doing a few simple bug fixes the other week, I thought I'd have a go at this as a bit of a larger project. I spent a few hours on it last week but have hit a roadblock and would be very grateful for any help. I've got the UI working for allowing edit of a parameter name, and changing the parameter name, but renaming the references to the parameter is proving to be a challenge. Here is where I am so far: I've managed to get to the point where re-ordering parameters works (ie, still works), or renaming parameters works, but doing both throws a NullReferenceException, and also hits a Debug.Assert in the renamer. The story so far:
I did notice that the Renamer class doesn't seem to have a heap of uses in the code, and unfortunately I no longer have access to the one Analyzer I wrote once that renamed fields so I can't remember how I achieved that. Any pointers as to where to go from here would be greatly appreciated. I could rewrite the body with my rewriter matching only on an identifiers name, and that would work, but then would break if there was another identifier with the same name (eg, field with the same name as parameter) and wouldn't account for renaming in local functions or named parameters. Thank you for reading! |
cc @dotnet/roslyn-ide |
Hey @davidwengier, nice progress! Are you still interested in this? Writing down some initial thoughts if you're still interested:
On line 26, you'll see the call to Then, when roslyn/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs Line 198 in 0c884ee
Now it gets slightly tricky. Here's what Rename does when renaming a parameter: ChangeSignature updates declarations & references to the invoked method and its overrides/etc. As you can see, Rename does not do that. There's also the case with an override that changes the parameter name, but we can deal with that later. So, if you want the parameter rename to cascade everywhere, either the Renamer needs updated (I don't think we should do this as part of this), or we need to do the rename manually as we visit each location and make whatever other changes are necessary -- for declarations just changing the name, and for references updating named arguments if necessary. This visiting & updating of each location is done for C# in the Service here: roslyn/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs Line 230 in 0c884ee
Let me know what you think! |
Thanks for the comments @dpoeschl. I admit I did abandon this because life got in the way, but I'm happy to keep plugging away. Thanks for the tip that Renamer is barking up the wrong tree too. I did change CSharpChangeSignatureService.cs as part of trying, and indeed it does do a lot of the work just by changing PermuteDeclaration like this: That works great for the method parameters etc. The problem I had was when trying to rewrite the body of the methods to change the usages of those parameters. I added a PermuteBody method and a ParameterRenamerRewriter to visit every identifier in the method body, and attempt to write out the new name. Unfortunately the identifiers do not match (presumably from two different syntax trees at that point) and I didn't know where to go from there. My attempt at matching was just this: If I change that to be naive and just match on identifier names (the ValueText property) alone, the code does work and everything changes as required, but obviously thats too naive and there a million ways it could be wrong. So what I really need help with is how to match identifiers from the ones that come in as part of the SignatureChange and the ones that are visited as the service is rewriting the tree. |
Also I need to work out how to get those cool inline code snippets :) |
Okay I found the I took the suggestion and reverted any changes to the I initially tried simply wrapping the Any suggestions for how to approach this without changing IParameterSymbol would be appreciated. |
Design review conclusion: this dialog was implemented in the current form to meet parity with prior releases as part of the minimum viable product for the initial Roslyn release. Expanding it in a well-defined manner seems like a good idea overall. The following items are especially valuable:
The following items would need to be separate issues due to additional design concerns:
🔗 Note that adding parameters is already filed as a separate issue in #33534. |
The latest version of ilasm produced by coreclr is now a fully independent executable; it no longer depends on having a full runtime laid down next to it. This means we can vastly simplify how it is deployde in our infrastructure. The package can now be included and have ilasm manually copied out. This is similar to the approach that we take for our diasymreader native dependencies. closes #37582 related #25930, #25144
There has been an ask to consolidate Change Signature feature requests into one issue. Since this enhancement is being tracked by the overarching issue #33977, will close as a dupe. |
It would be nice if while in the Change Method Signature you could change the modifiers, rename, and return type.
The text was updated successfully, but these errors were encountered: