vscode: Bad Syntax highlighting for BASH scripts
Type: Bug
- open at least 100 lines bash script on vscode 1.76
- open the same script on vscode 1.74 or older
- compare the syntax highlighting
VS Code version: Code 1.76.0 (92da9481c0904c6adfe372c12da3b7748d74bdcb, 2023-03-01T10:25:16.105Z) OS version: Linux x64 6.1.12-1-MANJARO Modes: Sandboxed: No
System Info
Item | Value |
---|---|
CPUs | 12th Gen Intel® Core™ i3-12100 (8 x 4100) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: disabled_software video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
Load (avg) | 1, 1, 2 |
Memory (System) | 31.14GB (26.02GB free) |
Process Argv | –unity-launch --crash-reporter-id ef5fac87-8bd1-43e0-9399-3463ed4f0075 |
Screen Reader | no |
VM | 0% |
DESKTOP_SESSION | gnome |
XDG_CURRENT_DESKTOP | GNOME |
XDG_SESSION_DESKTOP | gnome |
XDG_SESSION_TYPE | wayland |
Extensions (25)
Extension | Author (truncated) | Version |
---|---|---|
path-intellisense | chr | 2.8.4 |
gitignore | cod | 0.9.0 |
vscode-github-actions | csc | 0.24.4 |
git-cheatsheet | dzh | 1.4.4 |
gitlens | eam | 13.3.1 |
EditorConfig | Edi | 0.16.4 |
hadolint | exi | 1.1.2 |
shell-format | fox | 7.2.5 |
vscode-chatgpt | gen | 3.9.4 |
copilot | Git | 1.77.9225 |
vscode-pull-request-github | Git | 0.58.2 |
todo-tree | Gru | 0.0.224 |
gitattributes | has | 0.4.1 |
bats | jet | 0.1.9 |
bash-ide-vscode | mad | 1.34.0 |
vscode-docker | ms- | 1.24.0 |
makefile-tools | ms- | 0.6.0 |
material-icon-theme | PKi | 4.24.0 |
shellman | Rem | 5.6.0 |
bash-debug | rog | 0.3.9 |
code-spell-checker | str | 2.19.0 |
even-better-toml | tam | 0.19.0 |
vscode-readme-pattern | tho | 1.3.0 |
vscode-conventional-commits | viv | 1.25.0 |
vscode-icons | vsc | 12.2.0 |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyonecf:30548226
vsccc:30610678
pyindex848:30662994
nodejswelcome1cf:30587006
3biah626:30602489
pyind779:30671433
89544117:30613380
pythonsymbol12:30671437
vsccsb:30677849
funwalk2cf:30676044
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 33 (11 by maintainers)
@variabl3 thats actually an issue I wasn’t aware of. It was caused by the % sign at the front of an argument, thinking it was special (similar to a $). I pushed a fix just now, v1.5.4 of Better Shell Syntax. It actually corrected highlighting in some other test cases as well
Thanks @jeff-hykin for the explanation.
Getting my personal system working really was the point of the comment
I didn’t know that the BASH grammar was maintained by outsiders in their spare time (like you).
Have a nice day, and thanks again for your work.
Given that most of the issues in this thread have been addressed upstream and pulled into VS Code insiders (and that we’re starting our endgame next week). I’m going to close this issue and we can open new ones for individual issues as they arise.
@jeff-hykin Coming back late here, but I do see 1.6.1 in the VS Code extensions. Installing now… Boom! That’s beautiful my friend. This looks better than ever and the issue above is resolved.
By the way… I did not realize MS is using your model either! Thank you so much, Jeff! I write a ton of BASH for some very large projects and it’s nice to meet the person behind this. 😃 Cheers!
Encountered this as well when revising a script which hasn’t been edited since 2021. Wrote a quick “dummy” demonstration to demonstrate:
As you can see, line 4 where I removed the percent sign does not break highlighting, however line 10 which is left intact does indeed break it. Per the comments, line 4 is NOT functional and line 10 is functional.
@yunielrc I see, I suppose getting your personal system working wasn’t the point of the comment
Yeah, for full explanation the difference is the repos of the Typescript grammar and C# grammar are owned/maintained by MS, while most grammar repos are maintained/unmaintained by random people like me in our free time. For whatever reason MS doesn’t do any PR’s for the ones they don’t keep directly. When something goes wrong for a MS grammar, someone on the payroll is responsible for causing it and fixing it.
Languages “important” to MS, like C++, still have these kind of breakages though. I know because I also maintain the C++ syntax.
Thanks @alexdima ,
I’m looking at it right now.
Yeah if you could @akpircher that’d be helpful. Upstream is here: https://github.com/jeff-hykin/better-shell-syntax
@alexr00 would you like me to re-create my comment as an issue in the upstream repo?
@RedCMD
Oh I see now, yeah thats an issue with the ${1} part, it should have the
punctuation.section.bracket.curly.variable
on the {}'s. Also it looks like there’s just general problems with the tagging ($
tagged as a bracket) so I reworked it just now and published it asv1.5.0
.To everyone in this thread:
Thank you for your patience and bug reports! The reason for the increased number of issues in shell script syntax highlighting is that we’re switching to a new shell script grammar. The old one was no longer maintained, and the author of the new one has shown that they’re quick to respond to and fix grammar issues (they also maintain the C and C++ grammars). There’s always a little pain when we switch to a new grammar, but in the end we’ll get (and have already gotten) fixes for longstanding shell script syntax highlighting issues.
If you want to help out with this effort, please use the VS Code insiders build. I’m pulling in the upstream changes from https://github.com/jeff-hykin/better-shell-syntax as they come in so you’ll get fixes faster there. You’ll also help to catch new issues before they make it into the stable build.
Coming from the closed (older?!) duplicate #175837, and having tried the Insiders build as suggested, var highlighting has improved since v1.76.0, but:
;
1.75.1:
1.76.0:
1.77.0-insider:
@yunielrc, thank you for the screenshots and the sample. I tried it out, and it looks like it’s fixed in VS Code Insiders, where we’ve updated the shell script grammar already.
@ryapric would you be able to try out VS Code insiders and confirm whether the behavior is correct there for your file?
@karabaja4, your issue appears to be mostly related to using
( )
instead of{ }
for code blocks (ex. on line 16 and 18 of https://github.com/karabaja4/arch/blob/master/scripts/dns.sh). This is not fixed in VS Code Insiders. Opened upstream issue: https://github.com/jeff-hykin/better-shell-syntax/issues/49