vscode-highlight
vscode-highlight copied to clipboard
Last character in matching pattern not highlighted
I'm making a highlighter for Gruescript, a simple language to write text adventures. A typical line has a syntax like this:
tag room visited
It has a small set of commands and everything is separated by whitespace. To highlight the first word and the second word differently I write a regex like this (simplified for this report):
"^(tag) ([a-z0-9$_]*)" : [{ "fontStyle" : "italic" } , { "fontWeight": "bold" } ]
Regex testing tools like regexr.com tell me that the first group matches "tag" and the second group matches "room", as intended.
But the extension doesn't do that. It formats the first matching group correctly, and then it formats the second group except the last character:
tag room visited
There are a lot of variants in my code, and different decorations, but in every case the same thing happens: that second matching group gets decorated except its last character.
Not a terrible problem but it's a bit distracting. I apologize if I'm missing something obvious, I'm not a programmer. Thanks!
I am experiencing similar problem. And I am wondering whether this is a bug or I miss something in the regex.
Similar issue here. My regex is something like <(.*?)>
, and it highlights from the start, including the <
, but omits the last two characters: <foobar>. If I change it to <(.*?>)
, i.e. put the >
into the match group, it still highlights from the start, but now only omits the final character: <foobar>. It looks as if the length is correct, but the highlight is always anchored at the start. For @Pseudavid's issue, it's probably the space character between the groups that's causing it.
I've run into the same issue.
After some experimentation, I discovered that the issue comes about when the regex contains anything not wrapped in (capture group brackets)
To workaround the problem, ensure that ALL parts of your regex are wrapped in a capturing group with (capture group brackets)
See this screenshot below for the difference in two config that are the same, except for the (capture group brackets)
being added in the middle of the regex in the 2nd config...
I also found this old issue + an answer from the author: https://github.com/fabiospampinato/vscode-highlight/issues/46#issuecomment-605619903
...which mentions that it's in the readme (I also missed this initially too). So I guess maybe it's too hard to fix currently?
Well, that fixed it. Thank you!
...which mentions that it's in the readme (I also missed this initially too). So I guess maybe it's too hard to fix currently?
It's impossible to fix, you need to know where all characters are, if you don't know that you'll necessarily misalign things eventually.