Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

File watcher integration #5040

Merged
merged 58 commits into from
Jun 14, 2018
Merged

File watcher integration #5040

merged 58 commits into from
Jun 14, 2018

Commits on May 29, 2018

  1. [Core] Use .dylib for native file watcher

    Previously the native file watcher was statically linked into
    monostub. This meant that the unit tests were not using the native
    file watcher but the one provided by Mono. Switching to a dylib
    allows the unit tests to use the native file watcher. If the dylib
    is missing then the Mono file watcher will be used.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    594e27b View commit details
    Browse the repository at this point in the history
  2. [Core] Ensure native file watcher is used in tests

    Added test that checks the native file watcher is available in unit
    tests.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    f799628 View commit details
    Browse the repository at this point in the history
  3. [Core] Allow a solution to be monitored by the file watcher

    Added a simple way to register a solution so all files in its
    directories are monitored. Only file change events are passed to the
    FileService which are then raised as events by the FileService.
    Added some tests to verify that modify a project inside a solution
    or a file inside the project generates FileService FileChanged
    events. The tests that use Project.SaveAsync pass without the
    new file watcher since the FileService is called directly to
    notify file changes when SolutionItem.DoSave is called and
    MSBuildProject.SaveAsync is called, which uses TextFile.Write which
    generates the event. The direct calls to notify the FileService
    have not yet been removed.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    488bacb View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    09288dc View commit details
    Browse the repository at this point in the history
  5. [Core] Support file deletion notifications from file watcher

    Registering a solution with the file watcher will generate file
    remove events from the FileService. Note that currently file
    remove events are generated on saving a file which has not yet
    been addressed. The new tests also seem to break the
    SaveFileInProjectExternally test - no change event is fired when
    saving a file using TextFileUtility.WriteText.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    46aa507 View commit details
    Browse the repository at this point in the history
  6. [Core] Treat temp file rename as a change event in file watcher

    The TextFileUtility creates a temp file in the same directory as
    the file being saved but changes the filename so it starts with '.#'
    The native file watcher on Mac does not always generate a change
    event when a file is saved using the TextFileUtility so we treat
    a rename event of the temp file to the file being saved as a change
    event that will be raised by FileService.FileChanged. This fixes
    the SaveFileInProjectExternally test that was failing.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    fce1c38 View commit details
    Browse the repository at this point in the history
  7. [Core] WorkspaceItem now registers itself with the file watcher

    On opening a solution it has a file watcher created. When the solution
    is disposed the file watcher is removed.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    a988e9d View commit details
    Browse the repository at this point in the history
  8. [Ide] Use file watcher to detect changes instead of checking all files

    Removed the code that checked all the files belonging to open solution
    when the IDE lost focus, or a build was started, then checked for
    modified or removed files on regaining focus or the build completes.
    This is now handled by the file watcher for the solution. Note that
    in the case of the IDE losing focus the file events are frozen until
    the IDE gets focus again.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    7c2e513 View commit details
    Browse the repository at this point in the history
  9. [Ide] Fix file open in text editor being reloaded on save

    Check the last write time of the file before reloading it to
    handle change events being generated by the file watcher. Also
    no need to generate a file change event directly in the Document
    class since one is generated by the file watcher.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    34a011f View commit details
    Browse the repository at this point in the history
  10. [Core] Fix invalid cast after thawing FileService events

    When different FileService event types (e.g. copy followed by a
    change event) occurred when the FileService was frozen on thawing
    the attempt to merge similar events together would fail since the
    cast to EventData<TArgs> would not work for different event types.
    
    System.InvalidCastException: Specified cast is not valid.
      at MonoDevelop.Core.EventQueue+EventData`1[TArgs].ShouldMerge (MonoDevelop.Core.EventQueue+EventData other) in
    main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs:865
      at MonoDevelop.Core.EventQueue.Thaw ()
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    526186e View commit details
    Browse the repository at this point in the history
  11. [Core] Watch files outside the solution directory

    Handle projects and files that exist outside the solution directory
    when watching files. File watchers are now created for all directories
    that are needed instead of just for the solution's directory.
    Currently the directory information is cached in the WorkspaceItem
    and not updated when a new project or file is added or removed.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    aedbd57 View commit details
    Browse the repository at this point in the history
  12. [Tests] Dispose solution in file watcher test instead of removing it

    The test was directly removing the solution from the file watcher
    service. Now the solution is disposed which will remove the solution
    from the file watcher.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    cb7a257 View commit details
    Browse the repository at this point in the history
  13. [Core] Handle multiple solutions opened with file watchers

    Initial simplistic handling of multiple solutions being opened
    which share a common directory.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    4247c99 View commit details
    Browse the repository at this point in the history
  14. [Core] Normalize file watchers for multiple solutions

    Ensure that the directories watched are normalized so a directory
    is not monitored more than once which would result in duplicate
    file events being generated.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    1fc0361 View commit details
    Browse the repository at this point in the history
  15. [Core] Re-normalize file watcher directories on solution close

    This fixes the file watcher being disabled for a solution when
    another solution was closed and exists in a directory that is a
    parent of the other solution.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    9c2ccfb View commit details
    Browse the repository at this point in the history
  16. [Core] Allow directories to be watched

    Allow directories to be watched without having to have them belonging
    to a solution. This allows documents to be monitored for changes
    when they do not belong to a solution.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    f853afc View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    5180437 View commit details
    Browse the repository at this point in the history
  18. [Core] RootWorkspace now adds solutions to the file watcher

    Previously the workspace item was registering itself with the
    file watcher. This was causing tests to hang since some solutions
    are not disposed.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    7762eb3 View commit details
    Browse the repository at this point in the history
  19. [Core] File watcher now handles adhoc solutions being disposed

    Adhoc solutions are not registered with the file watcher and
    when they were disposed were triggering an update of the file
    watchers. Now a check is made to see if the solution is being
    watched before updating the file watchers.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    921a37e View commit details
    Browse the repository at this point in the history
  20. [Ide] Handle filename being changed with save as when being watched

    Refresh the file watchers after the file in the text editor is saved
    as another file somewhere else.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    1d1891b View commit details
    Browse the repository at this point in the history
  21. [Core] Update file watchers on project added/removed to/from solution

    Refresh the directories monitored when a project is added to a
    solution or removed from a solution.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    55fdc6e View commit details
    Browse the repository at this point in the history
  22. [Core] Update file watchers when solution added to workspace

    Refresh the file watchers when the workspace has a solution added to
    it or removed from it.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    b8857f5 View commit details
    Browse the repository at this point in the history
  23. [Core] Update file watchers after adding file to project

    When a file is added to a project or removed from a project the
    file watchers are now refreshed. Currently the logic is very simple -
    any file added or removed will cause a refresh. This could be improved.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    cf094b7 View commit details
    Browse the repository at this point in the history
  24. [Core] Fix no file reload when file modified externally

    Some applications, such as TextEdit.app, will create a backup file
    and then rename that to the original file. This results in no file
    change event being generated by the file watcher. To handle this
    a rename is treated as a file change for the destination file.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    9ec5506 View commit details
    Browse the repository at this point in the history
  25. [Core] Fix missing file change events

    The FileService was merging the file events to the previous event
    not the next one. So if there was one change for file 1 followed by
    a change for file 2 the FileService would lose the change for file 1.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    257395b View commit details
    Browse the repository at this point in the history
  26. [Core] Mark RootWorkspace.GetFileStatusTracker as obsolete

    File events are generated now for all open documents and solutions so the
    GetFileStatusTracker is not needed.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    8ba6603 View commit details
    Browse the repository at this point in the history
  27. [Git] Stop using FileStatusTracker when working with stashes

    The file watcher will now generate the required Changed and Deleted
    events. Freezing and Thawing the FileService to get the same behaviour
    as before when the FileService notifications were applied after the
    stash was applied.
    
    Behaviour is a bit broken here compared with before. The native file
    watcher seems to want to generate - FileChanged, FileCreated and
    FileDeleted. This results in any open documents that were changed
    by the stash to be closed. Previously these would be reloaded. The
    native file watcher gets a changed, created and deleted event flag
    in the same message and then fires three events - changed, created
    and deleted event even though the file exists.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    81c2083 View commit details
    Browse the repository at this point in the history
  28. [Core] Fix file removed event fired when file not deleted

    The native file watcher sometimes generates Changed, Created and
    Deleted events in that order from a single native file event. This
    can occur even when the file is not deleted. Sometimes you can
    trigger this behaviour using File.WriteAllText when the file does
    not exist. Now a check is made to ensure the file does not exist
    before the file watcher deleted event handler raises the FileRemoved
    event with the FileService.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    84d167a View commit details
    Browse the repository at this point in the history
  29. [Core] Fix failure to open Git Status window

    The Git StatusView indicates it has a file but the parent directory
    of the filename is null. This was not handled by the file watcher
    and resulted in the Git status window not being displayed. In the
    IDE log an IndexOutOfRangeException was thrown:
    
    Error while executing command: Review Solution and Commit
    System.IndexOutOfRangeException: Index was outside the bounds of the array.
      at MonoDevelop.Core.FilePath.IsChildPathOf (MonoDevelop.Core.FilePath basePath)
      in MonoDevelop.Core/FilePath.cs:180
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    1ed62bd View commit details
    Browse the repository at this point in the history
  30. [Core] Fix file not being closed when deleted externally

    Deleting a file externally on the Mac is treated as a move to the
    ~/.Trashes directory. This rename event was being ignored so the file
    was not being closed on switching back to the IDE. Now a delete
    event is fired by the FileService for the original file when it is
    renamed.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    904180e View commit details
    Browse the repository at this point in the history
  31. [Core] Improve speed of file watcher tests

    The tests were taking about 2 minutes to run. Now they take about 25
    seconds. The problem was that the tests were timing out when waiting
    for file events instead of continuing when a particular file event
    occurred.
    
    Also the native file watcher will sometimes generate file events out
    of sequence so this is now handled in the tests by waiting for multiple
    file events before continuing.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    98b9bd4 View commit details
    Browse the repository at this point in the history
  32. [Core] FileStatusTracker now uses FileService.FileChanged events

    The FileService.FileChanged events are now generated by the file
    watcher. The FileStatusTracker is used by WorkspaceItem and
    SolutionItem. It has been changed so that it uses the file changed
    event to detect if the item needs to be reloaded. Previously it would
    check the last write time of the item every time NeedsReload was
    called.
    
    The reload required event is not being generated - this was not
    being fired before.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    f3d4850 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    91cadcd View commit details
    Browse the repository at this point in the history
  34. [Core] Fix crash when trying to watch missing directory

    The native file system watcher will throw an ArgumentException in
    its constructor if the directory does not exist. So missing
    directories are now ignored when monitoring files. For example, a
    linked file might be in a directory that does not exist. An attempt
    was made to monitor this directory which would cause a crash.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    f23b71c View commit details
    Browse the repository at this point in the history
  35. [Core] Handle saving file externally generating events out of order

    Saving a file in TextEdit.app will sometimes cause a rename event
    out or order where the last rename is a rename of the original file
    to a temp file. This was causing the file to be closed in the IDE
    even though the file was not deleted. To handle this a check is made
    to ensure the file has been deleted before raising the FileService
    FileRemoved event.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    23f6e7c View commit details
    Browse the repository at this point in the history
  36. [Core] Fix project not being reloaded when changed externally

    Editing the .csproj file externally was not resulting in the project
    being reloaded in the IDE. The FileService.FileChanged event was
    used by the RootWorkspace before the FileStatusTracker processed
    the same event so the NeedsReload was not true. As a workaround
    the FileService.FileChanged event is registered by the workspace item
    first.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    fd56afd View commit details
    Browse the repository at this point in the history
  37. [Core] RootWorkspace now uses ReloadRequired events

    The RootWorkspace no longer uses the FileService.FileChanged to
    detect a reload is need for solutions or projects. Instead it uses
    the solution's ReloadRequired and ItemReloadRequired events. The
    ReloadRequired event is fired by the FileStatusTracker when the
    solution file is changed externally. The ItemReloadRequired event
    is fired by the FileStatusTracker for any solution item if its file
    is changed externally.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    8324211 View commit details
    Browse the repository at this point in the history
  38. [Core] File watcher now uses tasks

    Use a task when updating the file watchers. Previously the
    file watchers were updated on the UI thread. For large projects,
    such as Main.sln, this would block the UI for ~1.6 seconds.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    11e9704 View commit details
    Browse the repository at this point in the history
  39. [Core] Rely on file watcher for change events in PerformGeneratorAsync

    The Project's PerformGeneratorAsync no longer checks all the files
    in the project in order to generate file change events. This is now
    handled by the file watcher.
    
    PerformGeneratorAsync calls GetProjectFileTimestamps to get a list of
    files and their timestamps.  When the solution is loaded,
    PerformGeneratorAsync is executed in parallel for many files. The
    result is that generated files are all modified more or less at once,
    so when checking timestamps, all generated files will be detected as
    modified by all generators, so each generator will send change
    notifications for all modified files of all generators. That is, if
    the generator is run for N files, there will be NxN notifications of
    file changes.
    
    Using the file watcher with a Xamarin.Forms project seems to generate
    three file changed events for the .xaml.g.cs file.
    
    Fixes VSTS #619697 - UI freeze after opening solution
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    1f2aa30 View commit details
    Browse the repository at this point in the history
  40. [NuGet] Remove FileService notify calls

    Rely on the file watcher to generate file change events for
    packages.config, project.assets.json and project.lock.json files.
    
    Note that there occasionally the file watcher generates odd events
    which means a packages.config file is not reloaded. Seen some events
    after installing a new NuGet package as follows which resulted in
    the packages.config file not being reloaded.
    
    OnFileChanged: test.csproj
    OnFileRenamed: test.csproj -> packages.config.new.20180529140342
    OnFileRenamed: packages.config -> packages.config.old.20180529140342
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    7fdb2d4 View commit details
    Browse the repository at this point in the history
  41. [Core] Fix packages.config file not always being reloaded

    The native file watcher rename events seem problematic. On installing
    a NuGet package sometimes you see the following events:
    
    OnFileCreated: .#Test.csproj
    OnFileRenamed: .#Test.csproj -> Test.csproj
    OnFileChanged: test.csproj
    OnFileRenamed: test.csproj -> test/packages.config.new.20180529140342
    OnFileRenamed: test/packages.config -> test/packages.config.old.20180529140342
    
    The last two events do not seem correct. It seems that the wrong
    file names are being included in the rename event. The .csproj file
    is not being renamed to a temp packages.config file.
    
    To handle this a check is made to see if the original file still
    exists and if it does then the rename event is treated as a file
    change event instead.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    b8bffba View commit details
    Browse the repository at this point in the history
  42. [ConnectedServices] Remove use of FileService notify method

    This code does not seem to be called. Can rely on the file watcher
    for the file change event to be raised.
    mrward committed May 29, 2018
    Configuration menu
    Copy the full SHA
    fc5fb37 View commit details
    Browse the repository at this point in the history

Commits on May 30, 2018

  1. [Core] Rely on file watcher for file change notifications

    Removed direct calls to FileService.FileNotifyChanged. This is now
    handled by the file watcher.
    
    Fixed two tests that were failing due to this change. The Reload
    SolutionTests was failing since the file changed event was no
    longer being generated by the Solution's SaveAsync method. This test
    now uses the file watcher. The SaveProject_AfterModifying file
    watcher test was failing since it was relying on the FileService
    NotifyFileChanged method being called when the project's SaveAsync
    method is used.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    e860c92 View commit details
    Browse the repository at this point in the history
  2. [Ide] Rely on file watcher for file change events

    Remove calls to FileService.NotifyFileChanged since the file watcher
    will generate these events.
    
    RootWorkspace's FileStatusTracker still has calls that directly
    use the FileService however this class is obsolete and not used
    anywhere.
    
    The WelcomePageSection makes a direct call to FileService's
    NotifyFileRemoved. This would not be generated by the file watcher
    since the project may have been deleted before the IDE was opened.
    This call is a way to have the project removed from the recently
    used list.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    ed27a6f View commit details
    Browse the repository at this point in the history
  3. [DesignerSupport] Rely on file watcher for file change events

    Remove calls to FileService.NotifyFileChanged. The file watcher will
    generate these events now.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    704e89c View commit details
    Browse the repository at this point in the history
  4. [WebReferences] Rely on file watcher for file change events

    Removed calls to FileService.NotifyFileChanged when generating the
    web reference files. The file change events are raised by the file
    watcher.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    2c47d11 View commit details
    Browse the repository at this point in the history
  5. [Refactoring] Rely on file watcher for file change events

    Remove calls to FileService.NotifyFileChanged when refactoring
    changes code in files which are not open. The file watcher will
    generate file change events for these changes.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    56c0978 View commit details
    Browse the repository at this point in the history
  6. [C#] Rely on file watcher for file change events

    Removed use of FileService.NotifyFileChange from the
    CodeGenerationService. Only code that seems to call this is the
    GtkCore addin in the ActionGroupDisplayBinding. That code does not
    seem to work - it fails to create a valid syntax tree in
    ActionGroupDisplayBinding.CreateClass, the C# code analysis
    SyntaxFactory.GetConstructorInitializerThisOrBaseKeywordKind throws
    an ArgumentOutOfRange exception. Also the names used are empty
    strings.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    9e58661 View commit details
    Browse the repository at this point in the history
  7. [Ide] Fix UI hang when many files are deleted

    When there are a lot of FileService.FileRemoved events being
    generated the UI would hang whilst the favourited projects information
    was being saved in the properties file. Now a check is made to see
    if the favourites have changed and if not a save is not done. This
    fixes the UI hang if you remove a node_modules folder inside a
    non .NET Core project that contains thousands of files.
    mrward committed May 30, 2018
    Configuration menu
    Copy the full SHA
    4aa1cf0 View commit details
    Browse the repository at this point in the history

Commits on Jun 1, 2018

  1. [Git] Rely on file watcher for file change events

    Removed calls to the FileService for file change and remove events.
    Removed calls that directly reload documents in the IDE.
    mrward committed Jun 1, 2018
    Configuration menu
    Copy the full SHA
    0895d38 View commit details
    Browse the repository at this point in the history

Commits on Jun 11, 2018

  1. [Autotools] Rely on file watcher for file change events

    Remove calls to FileService.NotifyFileChanged when the makefile
    is updated. The file watcher will fire the file change events for
    makefiles in the project or solution directory.
    mrward committed Jun 11, 2018
    Configuration menu
    Copy the full SHA
    b417d4b View commit details
    Browse the repository at this point in the history
  2. [GtkCore] Rely on file watcher for file change events

    Remove calls to FileService.NotifyFileChanged. The file change events
    will be raised by the file watcher.
    mrward committed Jun 11, 2018
    Configuration menu
    Copy the full SHA
    12ab30c View commit details
    Browse the repository at this point in the history
  3. [Subversion] Rely on file watcher for file change events

    Removed calls to FileService.NotifyFileChanged. The file change
    events are not generated by the file watcher.
    mrward committed Jun 11, 2018
    Configuration menu
    Copy the full SHA
    63302cf View commit details
    Browse the repository at this point in the history

Commits on Jun 12, 2018

  1. [Core] Remove file watcher debug logging

    Also fix typo in file watcher comment.
    mrward committed Jun 12, 2018
    Configuration menu
    Copy the full SHA
    5cc345d View commit details
    Browse the repository at this point in the history

Commits on Jun 13, 2018

  1. [Core] Make FileService.ThawEvents thread safe.

    The ThawEvents method will now handle being called from a non-UI
    thread.
    mrward committed Jun 13, 2018
    Configuration menu
    Copy the full SHA
    85e867f View commit details
    Browse the repository at this point in the history
  2. [Git] No need to call FileService.ThawEvents on UI thread

    The FileService.ThawEvents method will now handle being called
    from a background thread.
    mrward committed Jun 13, 2018
    Configuration menu
    Copy the full SHA
    98a2508 View commit details
    Browse the repository at this point in the history
  3. [Git] Reload files when they are reverted

    Add back original code that reloaded reverted files that were open
    in the text editor. Without this change if the file is dirty then
    the file will not be reloaded and instead the text editor will
    show a message about the file being changed outside the IDE. Since
    the user explicitly asked to revert the file then the file should
    be reloaded automatically even if there are unsaved changes.
    mrward committed Jun 13, 2018
    Configuration menu
    Copy the full SHA
    a3d9526 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6066964 View commit details
    Browse the repository at this point in the history