@@ -416,55 +416,23 @@ function watch_manifest(mfile::String)
416416 @debug " Pkg" _group= " manifest_update" manifest_file= mfile
417417 isfile (mfile) || return nothing
418418 pkgdirs = manifest_paths (mfile)
419+ pathreplacements = Pair{String,String}[]
419420 for (id, pkgdir) in pkgdirs
420421 if haskey (pkgdatas, id)
421422 pkgdata = pkgdatas[id]
422423 if pkgdir != basedir (pkgdata)
423424 # # The package directory has changed
424425 @debug " Pkg" _group= " pathswitch" oldpath= basedir (pkgdata) newpath= pkgdir
425- # Stop all associated watching tasks
426- for dir in unique_dirs (srcfiles (pkgdata))
427- @debug " Pkg" _group= " unwatch" dir= dir
428- delete! (watched_files, joinpath (basedir (pkgdata), dir))
429- # Note: if the file is revised, the task(s) will run one more time.
430- # However, because we've removed the directory from the watch list this will be a no-op,
431- # and then the tasks will be dropped.
432- end
433- # Revise code as needed
434- files = String[]
435- mustnotify = false
436- for file in srcfiles (pkgdata)
437- fi = try
438- maybe_parse_from_cache! (pkgdata, file)
439- catch err
440- # https://github.com/JuliaLang/julia/issues/42404
441- # Get the source-text from the package source instead
442- fi = fileinfo (pkgdata, file)
443- if isempty (fi. modexsigs) && (! isempty (fi. cachefile) || ! isempty (fi. cacheexprs))
444- filep = joinpath (basedir (pkgdata), file)
445- src = read (filep, String)
446- topmod = first (keys (fi. modexsigs))
447- if parse_source! (fi. modexsigs, src, filep, topmod) === nothing
448- @error " failed to parse source text for $filep "
449- end
450- add_modexs! (fi, fi. cacheexprs)
451- empty! (fi. cacheexprs)
452- fi. parsed[] = true
453- end
454- fi
455- end
456- maybe_extract_sigs! (fi)
457- push! (revision_queue, (pkgdata, file))
458- push! (files, file)
459- mustnotify = true
460- end
461- mustnotify && notify (revision_event)
462- # Update the directory
463- pkgdata. info. basedir = pkgdir
464- # Restart watching, if applicable
465- if has_writable_paths (pkgdata)
466- init_watching (pkgdata, files)
467- end
426+ push! (pathreplacements, basedir (pkgdata)=> pkgdir)
427+ switch_basepath (pkgdata, pkgdir)
428+ end
429+ end
430+ end
431+ # Update the paths in the watchlist
432+ for (oldpath, newpath) in pathreplacements
433+ for (_, pkgdata) in pkgdatas
434+ if basedir (pkgdata) == oldpath
435+ switch_basepath (pkgdata, newpath)
468436 end
469437 end
470438 end
@@ -475,6 +443,53 @@ function watch_manifest(mfile::String)
475443 end
476444end
477445
446+ function switch_basepath (pkgdata:: PkgData , newpath:: String )
447+ # Stop all associated watching tasks
448+ for dir in unique_dirs (srcfiles (pkgdata))
449+ @debug " Pkg" _group= " unwatch" dir= dir
450+ delete! (watched_files, joinpath (basedir (pkgdata), dir))
451+ # Note: if the file is revised, the task(s) will run one more time.
452+ # However, because we've removed the directory from the watch list this will be a no-op,
453+ # and then the tasks will be dropped.
454+ end
455+ # Revise code as needed
456+ files = String[]
457+ mustnotify = false
458+ for file in srcfiles (pkgdata)
459+ fi = try
460+ maybe_parse_from_cache! (pkgdata, file)
461+ catch err
462+ # https://github.com/JuliaLang/julia/issues/42404
463+ # Get the source-text from the package source instead
464+ fi = fileinfo (pkgdata, file)
465+ if isempty (fi. modexsigs) && (! isempty (fi. cachefile) || ! isempty (fi. cacheexprs))
466+ filep = joinpath (basedir (pkgdata), file)
467+ src = read (filep, String)
468+ topmod = first (keys (fi. modexsigs))
469+ if parse_source! (fi. modexsigs, src, filep, topmod) === nothing
470+ @error " failed to parse source text for $filep "
471+ end
472+ add_modexs! (fi, fi. cacheexprs)
473+ empty! (fi. cacheexprs)
474+ fi. parsed[] = true
475+ end
476+ fi
477+ end
478+ maybe_extract_sigs! (fi)
479+ push! (revision_queue, (pkgdata, file))
480+ push! (files, file)
481+ mustnotify = true
482+ end
483+ mustnotify && notify (revision_event)
484+ # Update the directory
485+ pkgdata. info. basedir = newpath
486+ # Restart watching, if applicable
487+ if has_writable_paths (pkgdata)
488+ init_watching (pkgdata, files)
489+ end
490+ return nothing
491+ end
492+
478493function active_project_watcher ()
479494 mfile = manifest_file ()
480495 if ! isnothing (mfile) && mfile ∉ watched_manifests
0 commit comments