facelessuser / BracketHighlighter

Bracket and tag highlighter for Sublime Text
https://facelessuser.github.io/BracketHighlighter/
1.75k stars 245 forks source link

Problem with matching curly brace that is part of a Bash string equivalency test #627

Closed luckman212 closed 7 months ago

luckman212 commented 7 months ago

Description

BH seems to be incorrectly matching a curly bracket that is part of a Bash string equivalency test. Not sure if there's a workaround.

Here's a small example:

#!/usr/bin/env bash

res='{ "foo": 123 }'

if [[ ${res:0:1} != '{' ]]; then
  echo 1>&2 "error in response from API"
  exit 1
fi

Screenshot:

image

Support Info

facelessuser commented 7 months ago

It looks likes your syntax highlighter doesn't scope the bracket in question as a string. That context is necessary for BH to work properly. This seems like a syntax issue, not a BH Issue. It's possible if it is scoped as a common scope that should be ignored generally, we could alter the rule, but I suspect it should be a string and is just a syntax bug.

luckman212 commented 7 months ago

Thanks @facelessuser

So the "problem" is with the Bash syntax highlighter native to ST? I don't know if this is changeable? If it is, I don't know how to do it.

If we only change 1 character, curly brace { → letter a for example, there is no problem

if [[ ${res:0:1} != 'a' ]]; then
  echo 1>&2 "error in response from API"
  exit 1
fi

image

facelessuser commented 7 months ago

Turns out they are scoped, but not as a normal string. I couldn't tell because your syntax highlighter made them look all white as if they were not scoped.

Screenshot 2024-02-25 at 11 06 52 AM

So we have to update the single quote rule and double quote rule to look for the scope meta.string.regexp.shell and then tell the curly, round, and square rule to ignore meta.string.regexp.shell. Then it works:

Screenshot 2024-02-25 at 11 06 38 AM
luckman212 commented 7 months ago

Thanks - I don't have whatever plugin you seem to be using to show the scopes. And not sure how to edit the syntax rules either (never done it before). Do you suggest doing this? Or should I just leave this alone...

facelessuser commented 7 months ago

It can be done locally, but I'll be issuing an update to the rules, so you can wait until then.

facelessuser commented 7 months ago

@luckman212 fix has been released. Give package control time to see it though. It could take up to two hours.

luckman212 commented 7 months ago

@facelessuser Amazing, this is super helpful. Confirmed it's working.

Thanks for fixing on a Sunday 🚀

image