@jfcherng, Can you explain better what clear scopes does?
I will explain roughly how things like scopes get matched in BracketHighlighter (BH).
-
It is difficult to know if a "
is the start of of a string or the end, especially since BH searches a sliding window of the whole view. Things like {
are easy because it is clearly different from }
, so things like pure regex can be used with maybe some exclude scopes. So quotes, which have no clear difference between the opening symbol and the closing symbol don’t bother searching with pure regex, they use scope matching.
-
Scope matching is performed by looking at the scope under the cursor and determining if we have a bracket rule associated with that scope. If the scope is one of interest, we will get it’s full extent and then apply a regex to the start and end of that scope to see if the respective opening and closing is symbol is found. Now using the context of scope we know that the two symbols we found are the opening and closing of the string.
If forced to using something like regex exclusively, this is too difficult for BH as it can be difficult to tell if when we find a "
if it is a start or end. You can add some further logic by looking at whether or not a space or comma or something precedes or follows the quote to give some usage context to determine if it is an opening or closing, but this becomes less reliable. The most reliable method then is to start parsing the file from the very beginning to ensure we know when we get the start and end bracket, but we also have to add additional logic to BH to then be aware and count every other un-escaped quote as either opening and closing. Also, you will suffer a large performance hit as you have to start at the beginning of the file instead of using a sliding window.
I am assuming that this clear_scope
feature is breaking the string scope. If that is the case, this clearly breaks the algorithm for finding opening and closing symbols for things like quotes. I would have to come up with a way to add additional logic to crawl out from and grap adjacent scopes and then use some algorithm to determine if they are linked. This sounds like more work than I am probably willing to put in as it will also impact performance.
It might be possible to come up with a way to handle this, and still keep performance reasonable, but it would be a major change to the current algorithm. I assume I would need to search for symbols with regex at first and then apply more some advanced scope context logic to determine if the quote is appearing at the start or end of the scope fragment etc. This is just me thinking out loud, and I am not sure when I would even have time to implement something like this assuming I understand the cause of the issue listed in this thread.
I don’t know, I’d like to understand this problem more before I give an official statement how feasible mitigation from my side would be. And even if mitigation is possible, I have to find time to experiment with it and evaluate performance etc.