rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.91k stars 299 forks source link

VB6: Implement file watchers for external changes #5282

Open mansellan opened 4 years ago

mansellan commented 4 years ago

Justification When working with source control, syncing from the repository can cause files to be changed externally. There is currently no mechanism in the VBE to detect such changes and sync them to the current project.

Description For simplicity, this issue is limited to VB6, as it already stores files externally and lists them all in a project file. However, this could potentially be extended to VBA with additional work.

VB6 has no concept of external file changes, once a project has been loaded into the editor the in-memory representation of the project and all of its source files is considered canonical. If files are changed externally, they will be ignored at compilation and risk being overwritten if the component is saved in the VBE. The only way to pick up external changes is to unload the project and reload it again.

We can improve upon this. When the project is opened, we can examine either the VBProject or the vbp file and determine the location of all files on disk. We can then add file watchers to them, and (prompt to?) update the component when external changes occur. Where this would result in a conflict, a dialog similar to the one from modern VS could be used:

image

mansellan commented 3 years ago

Note that Visual Studio 2019 will reflect external changes immediately unless there are conflicts with unsaved changes in the IDE. I think this is probably the ideal. That said, as this changes the default behaviour of the IDE, it should definitely be configurable, and probably opt-in (at least initially).

In terms of implementation, this would require:

  1. Detect file change
  2. Check for modification of target component, then automatically (if clean) or by prompt (if dirty), either:
    • Remove and re-add the component from the project. This might cause a momentary "flash" in the project explorer, but is the only way to ensure the changes are imported with full fidelity (attributes etc).

We would also need to consider how to queue the reload so that it didn't happen in the middle of a parse.