-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand variable highlights to support Bash parameter expansion #20
base: master
Are you sure you want to change the base?
Expand variable highlights to support Bash parameter expansion #20
Conversation
* Add support for all of the existing Bats variables in ${var} form. * Add tests for each of the matches using various real-world examples. * Fix some existing tests
Hi, I'll see if I find an idea for the "intentional regression" while I'll review/test it. Thank you for real life examples ! I'm not developing much those days, this is valuable. Best |
Hi, For some reason I do not have permissions to run the bellow command. I've create a branch and apply the patch. lets see if it apply the PR merge when I push it back... Keep you posted. |
Hi @KlfJoat , I've pushed a KlfJoat-bash-parameter-expansion-highlight-support branch. I need to deep a bit on your "intentional regression" as I do not see impact on my tests. but I was more focus on the brace thing and I have not active projects using bats-core currently to made proper test. Regards |
Hi, Thanks for reviewing my PR. I checked and your edits to the regexes don't support syntax highlighting when the variable is involved in Bash Parameter Expansion. That's the test cases that look like... ${BATS_TEST_DIRNAME##*/}
${BATS_TEST_DIRNAME%/*}
${BATS_TEST_DIRNAME:1:2} Parameter Expansion allows users to manipulate the variable in various ways upon use. In those 3 examples...
It doesn't change the syntax highlighting of the braces at all. |
I'm not sure why. On my side it shows the repo as Public. I followed the standard GitHub PR workflow as best I can, but I don't use GitHub much for collaboration so I might have changed a setting somewhere else that affects it? Sorry. |
Hi, |
FYI, I did things like this to try to get the braces included, but they didn't work consistently. <dict>
<key>match</key>
<string>(\${(output|status|lines|stderr|stderr_lines))\b[^}]*(})</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>support.variable.bats</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>support.variable.bats</string>
</dict>
</dict>
</dict> This is the inconsistent styling I mentioned while trying to get the braces to be green. Despite the fact that the inspector says that the curly braces in every one of the examples is the same, and despite the fact that it says they're all colored green, they were not green on the screen. Personally, I think that having the variable name properly highlighted is the most important part. The dollar sign and braces are not desirable, IMO. |
Hi, I'm afraid I don't understand what the problem is that you're trying to solve. In my opinion, what we want to highlight green are the special Bats variables only. My PR does that. Your latest change highlights as green the Bash Parameter Expansion parts, which is undesirable. It also highlights some array indexes as green, which is also undesirable. I'm not saying my PR is perfect. But if I don't understand what your goal is, I can't help you to reach it. |
FYI, I just found an alternative way that could have helped you out with this, so I want to share it. GitHub creates git
Then you can fetch the PR and create a local branch... git fetch origin refs/pull/20/head:KlfJoat-bash-parameter-expansion-highlight-support Then |
Hi
I prefer to use the
${var}
form of variables in Bash. However, the current matches for this extension do not support that form except for counting variables for output variables, like${#lines[@]}
.This PR is some trivial work to help support both the
$var
and${var}
forms in Bats files, plus a little cleanup of the match file.This does introduce an intentional regression. Previously, the
$
would be included in thesupport.variable.bats
scope, and thus be given the same foreground style as the variable name. However, when expanding the matches to include the${var}
style, this lead to inconsistent styling of the braces, even when they were captured and given thesupport.variable.bats
scope.Similarly, I could find no way to collapse the matches down so the file had just 1 entry per variable list, without inconsistent styling of the braces. In this case, that would be open brace
{
red and closed brace}
yellow on the same${var}
, somehow.I have also updated the
test.bats
file, where I've added a pretty extensive "workout" of the syntax coloring. I'm using the color customizations recommended in the README.md file. Since the visual "tests" in this file were pass-only, I've kept with that convention. However, I did some failing visual tests of my own and they all failed properly.Finally, there were a few tests that seemed to be missing or incorrect, and I corrected them.