Skip to content
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

Incorrect bash/zsh syntax highlighting #147673

Closed
VorpalBlade opened this issue Apr 19, 2022 · 3 comments
Closed

Incorrect bash/zsh syntax highlighting #147673

VorpalBlade opened this issue Apr 19, 2022 · 3 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) grammar Syntax highlighting grammar upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@VorpalBlade
Copy link

VorpalBlade commented Apr 19, 2022

Issue Type: Bug

Vscode gets confused by the following fragment of zsh code (where the first line is taken verbatim from the _arguments completion helper code that is bundled with zsh):

"${(@)^${(@)tmp:#^*:*}//:/[}]"
# This part should not be in the string in zsh

The second line (and everything after in the file) is incorrectly considered part of the string by VSCode's shell syntax highlighting. For some to me unfathomable reason it appears VSCode does not properly detect the end quote of the string on the first line.

Here is how it looks in vscode:
image

Removing the last ] in the string "fixes" the highlighting (but of course breaks the code):
image

VS Code version: Code 1.66.2 (dfd34e8, 2022-04-11T07:49:24.808Z)
OS version: Linux x64 5.17.3-arch1-1
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (8 x 2816)
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
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 1, 1, 0
Memory (System) 31.12GB (24.32GB free)
Process Argv --disable-extensions --crash-reporter-id a77f92e1-4f12-4a9f-aad2-4dc61886222c
Screen Reader no
VM 0%
DESKTOP_SESSION cinnamon
XDG_CURRENT_DESKTOP X-Cinnamon
XDG_SESSION_DESKTOP cinnamon
XDG_SESSION_TYPE x11
Extensions disabled
@VorpalBlade
Copy link
Author

VorpalBlade commented Apr 19, 2022

After debugging this I believe the issue may be that VSCode gives higher "precedence" to [] than {}. I believe that the [ and ] at the end in the code are in fact unrelated (though I admit the code is hard to read!).

"${var//:/[}]"

is a simplified example that still exhibits the issue. The correct interpretation of it is

  1. $var but with all : replaced with [
  2. A final ] outside the variable substitution.

Zsh processes nested substitutions from inside out, so the whole ${...} is processed before ] is considered, and a lone ] at the end of the string is a normal literal character (as is the [ in the replacement string of the //search/replace section), nothing fancy going on.

@VorpalBlade
Copy link
Author

By the way, this is not zsh specific, I can reproduce this with the following bash code, which also syntax highlights incorrectly in vscode in the same manner:

v="a:b"
echo "${v/:/[}]"
# Prints a[b]

@VorpalBlade VorpalBlade changed the title Incorrect zsh syntax highlighting Incorrect bash/zsh syntax highlighting Apr 19, 2022
@mjbvz mjbvz assigned alexr00 and unassigned mjbvz Apr 19, 2022
@alexr00
Copy link
Member

alexr00 commented Apr 20, 2022

We get our shellscript grammar from https://github.com/atom/language-shellscript, but the textmate grammar there is no longer maintained. This issue would need to be solved by adopting a new shellscript grammar: #77675

@alexr00 alexr00 closed this as completed Apr 20, 2022
@alexr00 alexr00 added upstream Issue identified as 'upstream' component related (exists outside of VS Code) *duplicate Issue identified as a duplicate of another issue(s) grammar Syntax highlighting grammar labels Apr 20, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) grammar Syntax highlighting grammar upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants