Gruntfuggly / todo-tree

Use ripgrep to find TODO tags and display the results in a tree view
Other
1.4k stars 134 forks source link

Duplicate issues in TODOs view when changing view modes #833

Open baincd opened 3 months ago

baincd commented 3 months ago

Recreate

Setup

Both the todo saved in the file ([ ] Hello) and the todo in the editor ([ ] Hello World) are displayed image

Click refresh cleans up the duplicate (removing the version saved to disk). But pressing the flat/tree/tags-only or group-by-tags button again reintroduces the extra todo

baincd commented 3 months ago

This issue seems similar to #637. I was able to track down the starting place for this issue (the refresh() function in src/extension.js), but I am unable to find the root cause.

However, I tried applying similar fixes to this issue as was used to fix #637, and they do appear to fix the issue. I haven't considered the performance impact of rebuilding the tree when changing the view mode, so that may need to be taken into consideration.

src/extension.js
@@ -863,12 +863,18 @@ function activate( context )
     function refresh()
     {
         searchResults.markAsNotAdded();

         provider.clear( vscode.workspace.workspaceFolders );
         provider.rebuild();

-        refreshOpenFiles();

-        addResultsToTree();
+        // FIX1 - just rebuild the entire tree
+        rebuild();
+
+        // OR FIX2 - call these methods the same was as is done in rebuild(), but without having to do the full rebuild
+        iterateSearchList()
+            .finally( refreshOpenFiles )
+            .then( addResultsToTree );
+
         setButtonsAndContext();
     }