This project is read-only.

ICodeRefactoringProvider.GetRefactoringsAsync is never invoked

Topics: APIs
Apr 8, 2014 at 11:33 AM
I'm playing with ICodeRefactoringProvider but I'm stuck. Even the ImplementNotifyPropertyChangedCS example does not work: the GetRefactoringAsync method never gets called. I checked the class is properly instantiated and the ICodeRefactoringProvider contract is properly exported.

I spent 3 hours diagnosing but without success.

Please advice :)

Thanks.
Apr 8, 2014 at 6:12 PM
Refactorings are not called automatically the way that diagnostics are. They should be called when you hit "Atl+." (to complement the "Ctrl+." that we use for diagnostic fixes.

Is that the problem that you were seeing?
Apr 8, 2014 at 6:48 PM
Yes, that was it. Wow, this was completely unintuitive to me. I spent hours diagnosing and it did not even come to my mind that I could press Alt+. when the light bulb was not displayed. Maybe I'm too accustomed to the ReSharper UX.

I really want the light bulb to be visible when the caret is in the hot spot, but I don't want any text adornment. The reason is "commercial": I want users (at least our free users) to see the features they could use. This is our marketing "push". A feature does not exist if they don't see it. That's why I need a mechanism that is more intrusive than Alt+. and less intrusive than squiggles. I was able to implement this behavior with smart tags but this was of course more difficult.
Apr 8, 2014 at 6:53 PM
You can achieve the same effect with the current Roslyn preview by creating a diagnostic with the Category of "Hidden". We will not present any UI for diagnostics like this, and then move all of your logic to the FixProvider.

However, it's not really what we are going after. The user model we envisioned is that diagnostics are things that you should fix, while refactorings are things that you might want to do.

I'm not a ReSharper user, but I was under the impression they had the same split - Alt+Enter for quick fixes and Ctrl+1 for refactorings.
Apr 8, 2014 at 7:25 PM
Thanks.

ReSharper has a pull mechanism, but it pushes a lot to the UI surface, including some refactorings or code generation options. I think that pushing is important to create awareness, and that's what all vendors are struggling for. If we care to develop a feature and got a developer to download our product, we want to make sure the developer is aware of our features.

The "Hidden" category makes the trick. Is it the official way to address this concern?
Apr 8, 2014 at 9:53 PM
It's as official a way as we have right now :)