Closed baincd closed 1 year ago
Hi @Gruntfuggly ,
Is there anything I can do to assist to get this fix merged into todo-tree? It would be nice to squash this annoying bug, and this PR provide what I think is a good fix. Please let me know - I'm happy to help in any way I can!
Thank you again for all your hard work on this awesome extension!
Thanks for this - I always have auto save enabled, so I never noticed this.
Totally understand. Happy I could help. Thank you!
The root cause of this issue is in rebuild().
refreshOpenFiles() removes current tree entries before adding entries from the file buffer, so this should execute after entries are added from the files on disk. At first glance this appears to be how it is coded, because iterateSearchList() is called before refreshOpenFiles().
However, iterateSearchList() calls search(...) which uses ripgrep.search(...), and ripgrep.search actually returns a Promise. This causes the thread of execution to return to rebuild(), which then executes refreshOpenFiles(). After refreshOpenFiles() completes (having added tree entries based on the file buffer), then the promises from ripgrep.search(...) are resolved and tree entries from the files on disk are added.
To fix this, I rewrote search(...) and iterateSearchList() to return Promises. Then in rebuild(), refreshOpenFiles() is executed only once the promises from the ripgrep.search(...) are resolved.
Resolves #637