fsprojects-archive / zzarchive-VisualFSharpPowerTools

[ARCHIVED] Power commands for F# in Visual Studio
http://fsprojects.github.io/VisualFSharpPowerTools/
Apache License 2.0
310 stars 77 forks source link

Highlight usages and Rename refactoring don't work for added/renamed files #68

Closed vasily-kirichenko closed 10 years ago

vasily-kirichenko commented 10 years ago

If we add a new file into a project or rename an existing file, Highlight Usages and Rename refactoring both stop working (in that particular file only).

The issue is obviously caused by the recently added ProjectProvider cache and was predictable at the time it was added.

If nobody knows a better approach, I'm going to add a FileSystemWatcher for each F# project in the cache and remove ProjectProvider from the cache if anything in a project file changed.

dungpa commented 10 years ago

What if we check for Project.Saved property in the agent and invalidate the cache if there is something changes? See http://msdn.microsoft.com/en-us/library/envdte.project.saved.aspx

We might have to call Project.Save() function in order that ProjectParser reads the fsproj files correctly.

vasily-kirichenko commented 10 years ago

The documentation reads:

A Boolean value indicating true (default) if the object has not been modified since last being saved or opened; false if otherwise.

So, if the user added/renamed a file and saved the project, the Saved property will be true and we cannot detect the change. In other words, this algorithm is unreliable.

What we need is some notification.

dungpa commented 10 years ago

I see. We need some events.

I prefer to use VS events since they are more reliable and optimal for the purpose. It seems to be possible (see http://social.msdn.microsoft.com/Forums/vstudio/en-US/ce46b411-96c3-496c-95b2-8042cc9b086e/projectitemsevents-not-firing?forum=vsx).

Let's try these internal events. We can fallback to FileSystemWatcher if there's no better alternative.

vasily-kirichenko commented 10 years ago

I managed to subscribe for C# project item events and it works: https://github.com/vasily-kirichenko/FSharpVSPowerTools/commit/2decc72e2cede0d092fbd6d5a8b6b983d5686ba1#diff-fb00f70c863ec08b0adf3196408186a7R119

The sad part is that there's no FSharpProjectItemsEvents object (dte.Events.GetObject("FSharpProjectItemsEvents") failed).

So, I'm stuck on this stage.

dungpa commented 10 years ago

You might be able to get it by casting to Events2 (see http://stackoverflow.com/questions/2837228/how-can-i-listen-for-the-deletion-of-a-projectitem-via-dte).

If it doesn't work, we have to try http://msdn.microsoft.com/en-US/library/microsoft.visualstudio.shell.interop.ivshierarchyevents_members(v=vs.80).aspx which is really primitive :(.

vasily-kirichenko commented 10 years ago

Thanks, the thick with Events2 seems to work. Wait for a PR soon.

vasily-kirichenko commented 10 years ago

I managed to listen for events and remove stailed ProjectProvider from the cache, but an exception occurred as Highlighting tries to work. See https://github.com/fsprojects/FSharpVSPowerTools/pull/72 Any ideas?

vasily-kirichenko commented 10 years ago

I fixed it. Maybe it's not as efficient but it works. Please review https://github.com/fsprojects/FSharpVSPowerTools/pull/72

vasily-kirichenko commented 10 years ago

After merging "Navigate to" PR this bug is back.