Adding an option to always highlight unmatched brackets

I would like to add an option to always highlight unmatched brackets/braces/parentheses, rather than only highlighting the one next to the cursor. I’ve prototyped two solutions:

  1. Apply a bookmark to each bracket in the document using setBookmark() - initially for the whole doc, then incrementally by listening to the “changes” event and only updating bookmarks for the modified lines. This is faster and requires less code than approach 2, but I wanted to confirm if it’s safe to set so many bookmarks (potentially thousands) in one file. Seems fine in my testing.

  2. Do not store any bracket related state, and only highlight bookmarks in the visual range. Scan before and after the visual range to see if there is any match. The disadvantage is that in the worst case it can require a scan of the entire document. Doing it async in small batches keeps the app responsive, but it can take a while for the highlight to show up.

I’ll send a pull request with my proposed changes, but wanted to check first to see if you have any concerns with approach 1, which seems better to me.

This is not a feature I’m willing to work on or include in my distribution, but you are of course free to build and distribute it yourself.

I’d only apply bookmarks to actual unmatched brackets, so save on the amount of bookmarks. They are cheap, but not free. Constraining your scan to the visible range might help, but note that sometimes you really don’t know whether something matches until you’ve scanned most of the document. You might want to keep some data structure describing the braces in the document, and update that on change events.

Did you implement that in the end? I’d like to show it to my user too on demand.