Todo-tree: Add support for Haskell comments

Created on 12 Dec 2020  ยท  18Comments  ยท  Source: Gruntfuggly/todo-tree

This is an excellent extension which I use frequently.
However, I have noticed that it does not support the -- single-line comment and {- multi-line comment -} format for Haskell.

Would it be possible for these comment formats to be added?

enhancement fixed

All 18 comments

I got it to almost work perfectly with setting the regex to ((--\s*($TAGS))|\{-\s($TAGS).*(\n.*)*-})

That matches single line comments OK, and multiline comments, except that it includes the -}.

Well that RegEx looks good to me! Haskell comments behave exactly the same as C-style single- and multi-line comments, so the RegEx's should be identical, but replace // with -- and /* */ with {- -}

I would've attempted to make a PR myself, but I'm not too good with web technologies, so I couldn't really make heads or tails of the source. ๐Ÿคทโ€โ™‚๏ธ

None the less, thankyou for addressing the Haskell comments.

For the record, I've just checked what you said about mutli-line Haskell comments picking up the final -}, and there is a similar behaviour in your C-style comments:
image
Results in:
image

I'm not sure if this is a known behaviour, but I thought I would bring it to your attention. I can move it into a new issue if you would like ๐Ÿ˜Š

Yes, I'm not surprised it does something similar.

It works slightly easier with C style comments, because most people use something like ** or * on each line between the markers too, which makes it easier to write the regex. Really, it just needs to match every thing but not including the -} over multiple lines - I just haven't managed to get it working on regex101 yet! ๐Ÿ™‚

If I get it working, I'l add it to the wiki.

Thankyou very much, best of luck! ๐Ÿ˜

I think I've finally got something working. It's a bit of a hack, but it seems to work.

I've just uploaded version 0.0.207 - let me know if it works, I guess using the regex from above.

I've added the regex to the wiki too.

It definitely seems to work for the multiline comments for the most part. On my machine, but only for the multi-lines as the changelog reflects.
image

FWIW, my TODO's are coloured orange because of the extension Better Comments by Aaron Bond, and it appears it recognises single line Haskell comments. Could be worth checking out that GitHub, since his seems to recognise Haskell single lines also.

Thankyou for the work you've put in! This is a great extension. ๐Ÿฅณ๐Ÿฅณ

What is your regex set to? With the one in the post above, it works for both single and multi line for me:
image

It would need some further changes to recognise the multi-line comments with the single line comments within them though.

Hmm - there is definitely something weird going on - with my test case it only finds the first multi-line TODO.

Will investigate...

I had a look at Better Comments and it looks like it searches with several passes - single line comments first, then multiline comments. Unfortunately I can't take that approach because I uses ripgrep to do the search in one go, so the regex has to accommodate everything at the same time. Makes it more complex unfortunately.

Just switched to the regex you posted earlier in the thread and it does work for the single line TODO's! Hopefully soon you can find a regex that consistently for both.
I'll take a look if I can find some time, I must admit though I do not have much experience with regex.

I've made some more improvements. It struggles with this case though:

{-
 TODO
  The 'square' function squares an integer.
  It takes one -} argument, of type 'Int'.
-}

because it considers the 'match' to be the first line, with everything else as 'extra stuff'. So the tree gets populated with a "{-" node and the remaining lines as children.

It reveals a bit of a problem - ripgrep returns results line by line for multiline searches, but there is nothing that links links to a single regex match. Currently the extension processes the results in reverse order until it matches a tag, at which point it decides everything up to that point was a single result. So in the above case, the {- gets lost. I'll have to see if there is another way to do it.

OK - I've made some updates to hopefully improve it. Would you be prepared to do a bit of beta testing for me?

Please unzip and install the attached (from the "Install from VSIX..." option on the Extensions view):
todo-tree-0.0.209.vsix.zip

Then, set

"todo-tree.regex.enableMultiLine": true

and

"todo-tree.regex.regex": "((--\\s*($TAGS))|\\{-[\\s\\S]*?($TAGS)[\\s\\S]*?-})"

Let me know how well it works. ๐Ÿ™‚

OK, I've pushed the changes anyway. Let me know if you have any issues with 0.0.209.

This seems to work without issue! ๐ŸŽ‰

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rickstaa picture rickstaa  ยท  5Comments

emanuelenardi picture emanuelenardi  ยท  3Comments

ghost picture ghost  ยท  7Comments

jabacchetta picture jabacchetta  ยท  8Comments

WORMSS picture WORMSS  ยท  6Comments