vscode-highlight icon indicating copy to clipboard operation
vscode-highlight copied to clipboard

Last character in matching pattern not highlighted

Open Pseudavid opened this issue 2 years ago • 4 comments

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!

Pseudavid avatar Jul 17 '22 12:07 Pseudavid

I am experiencing similar problem. And I am wondering whether this is a bug or I miss something in the regex.

esonec avatar Jul 25 '22 03:07 esonec

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.

cruegge avatar Aug 04 '22 10:08 cruegge

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...

2022-08-16_132557 - scratch-notes - 2022-08-16_13 06 33 md - Visual Studio Code

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?

hi2u avatar Aug 16 '22 03:08 hi2u

Well, that fixed it. Thank you!

Pseudavid avatar Aug 16 '22 19:08 Pseudavid

...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.

fabiospampinato avatar Nov 15 '22 21:11 fabiospampinato