Gruntfuggly / todo-tree

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

Be able to regexp filter tree #659

Closed nacesprin closed 1 year ago

nacesprin commented 2 years ago

image

At now we only filter by one word. It would be handly to filter for more than one word. For example: TODO and CONTINUE options, or whatever I want.

Gruntfuggly commented 1 year ago

This might be a reasonably simple enhancement, so I'll try and add it.

Gruntfuggly commented 1 year ago

Not sure when I implemented this, but it already works. E.g. (TODO|CONTINUE) should work as you expect.

nacesprin commented 1 year ago

TL;DR; the filter is filtering by words in the TODO comment line, but not by TODO keyword

The filtering option is not working as expected. Steps to reproduce:

1) This is my TODO tab: image

2) Filtering by TODO keyword. Expected: view TODO keyword results. Shown: nothing, because there is not any comment which contains TODO word image

image

3) Filtering by something word Expected: nothing, because there is no something keyword Shown: results by containing something word. It should not be thrown because something is a word of a comment, not a KEYWORD image

image


Filtering by word it's fine, but I thing it should be also filter by KEYWORD too

Gruntfuggly commented 1 year ago

Ah I see - yes, at the moment it only includes the leaf nodes, not the folder nodes. So what would be the desired behaviour? If it matched a keyword, would you expect all it's children to be shown or just the node itself?

nacesprin commented 1 year ago

Thanks Nigel. I suppose a checkbox inside the filter dialog to choose between "folder nodes" / "leaf nodes" options would be handy. Then depending of the user selection, will filter it.

nacesprin commented 1 year ago

Or another 3rd option like "both" to filter in both ways.

frypf commented 1 year ago

TL;DR; the filter is filtering by words in the TODO comment line, but not by TODO keyword

I only witness this when grouping by tag. I don't tend to use that option normally - even less now since I've realised I could filter by tag - so it seemed to be working fine as far as I could tell until I played around a bit with different options.

On a related note, is there any way to pass a regex as a string arg directly to the todo-tree.filter command? Being able to assign a keybinding to quickly bring up a list of solely TODO items / project marks / HACKs or whatever without having to type out the different regexes each time would be super-useful.

frypf commented 1 year ago

Had a quick test on a local build, and on the face of it making a small change here seems to do the trick wrt passing an arg directly to the filter:

context.subscriptions.push( vscode.commands.registerCommand( 'todo-tree.filter', function( argTerm )
{
-    vscode.window.showInputBox( { prompt: "Filter tree" } ).then(
+    if (argTerm == "") argTerm = undefined;
+    Promise.resolve(argTerm ?? vscode.window.showInputBox( { prompt: "Filter tree" } )).then(
        function( term )

I'm not sure how that might play out with the proposed addition of the checkbox idea though.

Gruntfuggly commented 1 year ago

I don't think adding a checkbox is possible - the API doesn't provide anything for that, so it would probably need to be a config option.

Perhaps it should be a separate filter command altogether - "Filter Tree Tags" - which would just apply the filter to the tag nodes?

Gruntfuggly commented 1 year ago

I'll see if I can add the argument - seems like a simple thing to add.

frypf commented 1 year ago

I'll see if I can add the argument - seems like a simple thing to add.

That'd be awesome, thanks very much. I looked at it again this afternoon and was wondering if it might also be possible to add an extra setting "todo-tree.tree.showActiveFilters", (similar to "todo-tree.tree.showCurrentScanMode") to optionally remove the filterStatusNode from the list. I like the idea of being able to navigate the list with cursor keys as discussed in #730 (I already have something similar working via a macro with vscode-commands), and I feel this would work really well in consort with that proposed change. In terms of making sure the list still indicates when a filter is active, the filter button already changes to show this, but I've also tinkered with making sure that the node is always shown if an active filter fails to match anything. I'm happy enough to attempt a pull request or just post some diffs if you feel this might work - the changes are pretty minimal.

I don't think adding a checkbox is possible

Having looked again at the API doc today, I was coming to the same conclusion. I'd be fine with separate commands, not sure how it may suit other peoples' use-cases? ~I was wondering is there any way of fuzzy-searching (live-filtering as you type) within a list view, or is that only available to the quick picker?~ (I've since found out this functionality is already available directly for keybindings via VSCode's list.find command since v1.70.)

frypf commented 1 year ago

I had a look again at adding filterTags as a separate command - it struck me it might be better to do this one as a straight tagList.includes(node.tag) rather than applying a regex comparison. My interpretation also expands any given tagGroups to avoid having to specify a massive long list every time.

I actually had some regex-reserved characters in some of my tags, which had caused no issues when passed to ripgrep but I couldn't figure out how to escape them properly for the js string-to-regex conversion performed by the current filter function. This avoids having to worry about any of that, and I've just left the original todo-tree.filter command mostly as-was (other than the addition of accepting args and now only matching against node.after).

Please feel free to look at my fork if it's of any interest.