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

Broken syntax highlighting for Bash associative arrays (VS Code v1.75.0) #173216

Closed
caleb531 opened this issue Feb 2, 2023 · 10 comments
Closed
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@caleb531
Copy link

caleb531 commented Feb 2, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.75.0
  • OS Version: macOS Ventura 13.2

Today, when I upgraded to VS Code 1.75.0, I noticed that the syntax highlighting for one of my shell files was broken, even though the syntax is correct (please see screenshots below). I do not recall this issue being present in releases prior to 1.75.0 (although all my devices have upgraded, so I am unable to confirm this).

I have disabled all my extensions, and the issue is still reproducible.

Steps to Reproduce:

  1. Open a new document
  2. Set the language mode to Shell Script
  3. Create an associative array in Bash where the key names are strings are the values contain spaces (see below); note that VS Code thinks there is an unterminated string somewhere (but there isn't)
#!/usr/bin/env bash

declare -A juices=(
    ['apple']='Apple Juice'
    ['orange']='Orange Juice'
)

# This is a comment
echo "${juices['apple']}"

You can also see a real-world example of this by pasting https://github.com/caleb531/dotfiles/blob/main/terminal/bash/build_cmds.sh into VS Code.

Screenshots

1

2

3

@RedCMD
Copy link
Contributor

RedCMD commented Feb 3, 2023

Can confirm it working correctly in 1.72.2
but has been broken in 1.75.0

Prob should move report to https://github.com/jeff-hykin/better-shell-syntax
already fixed? jeff-hykin/better-shell-syntax#29

related: #173224

@tikkanz
Copy link

tikkanz commented Feb 3, 2023

I had the same issue (highlighting of associative arrays was broken after upgrading to 1.75.0).
Installing the jeff-hykin/better-shell-syntax extension as mentioned by @RedCMD worked to resolve the issue for me in the meantime. Would be good to fix the default highlighting (without Extension) in VSCode.

@WinkelCode
Copy link

Code_LoBz9SGI8p

The issue appears to affect just arrays in general if a value contains a space.

@caleb531
Copy link
Author

caleb531 commented Feb 4, 2023

To @tikkanz's point, jeff-hykin/better-shell-syntax does help a bit, although it's still not perfect.

Screenshot 2023-02-04 at 11 12 51 AM

@alexr00
Copy link
Member

alexr00 commented Feb 6, 2023

@caleb531 can you share a copy/pastable snippet of what you're seeing in #173216 (comment) so we can reproduce the issue easily? VS Code insiders will have the latest from https://github.com/jeff-hykin/better-shell-syntax tomorrow, and the recovery release of 1.75.1 will bring back the grammar from 1.74 (#173336).

@alexr00 alexr00 added info-needed Issue requires more information from poster and removed new release labels Feb 6, 2023
@caleb531
Copy link
Author

caleb531 commented Feb 6, 2023

@alexr00 When better-shell-syntax is enabled, the issue is fixed if I assign to the variable on the same line as the declare:

declare -A build_cmd_map=(
	['gulp:build']='gulp build'
	['gulp:clean']='gulp clean'
	['gulp:develop']='gulp serve'
	['gulp:watch']='gulp build:watch'

	# this is a comment
	['node:start']='npm start'
	['node:build']='npm run build'
	['node:watch']='npm run watch'
	['node:develop']='npm run dev'
	['node:preview']='npm run preview'

	['jekyll:build']='jekyll build'
	['jekyll:develop']='jekyll serve'
	['jekyll:watch']='jekyll build --watch'
)

Screenshot 2023-02-06 at 9 38 35 AM

However, if I assign separately (which still executes fine in my shell), then the syntax breaks:

#!/usr/bin/env bash

declare -A build_cmd_map=
build_cmd_map=(
	['gulp:build']='gulp build'
	['gulp:clean']='gulp clean'
	['gulp:develop']='gulp serve'
	['gulp:watch']='gulp build:watch'

	# this is a comment
	['node:start']='npm start'
	['node:build']='npm run build'
	['node:watch']='npm run watch'
	['node:develop']='npm run dev'
	['node:preview']='npm run preview'

	['jekyll:build']='jekyll build'
	['jekyll:develop']='jekyll serve'
 	['jekyll:watch']='jekyll build --watch'
)

Screenshot 2023-02-06 at 9 39 19 AM

@alexr00
Copy link
Member

alexr00 commented Feb 7, 2023

Thanks @caleb531. I pulled the latest changes from the folks in jeff-hykin/better-shell-syntax into VS Code yesterday and I see both of your examples work now. If you want to use VS Code insiders then the issue should be resolved there. Or, I assume that jeff-hykin/better-shell-syntax will have another release of the extension with the fix at some point in the near future.

@alexr00 alexr00 closed this as completed Feb 7, 2023
@cipherdmg
Copy link

cipherdmg commented Mar 12, 2023

This is still broken.

Build 1.77.0-insiders (just updated today).

Doing this breaks syntax highlighting. The only way for me to stop breaking it is if I put a escape the second entry in the array which is not valid syntax. The issue is that second red bracket. If I escape it then the colors are fine but again thats not valid.

declare -A fileKeyFileMap=(["${VAR1}"]="${VAL1}" ["${VAR2}"]="${VAL2}")

I moved back down to 1.7.6 stable and its working ok there.

So is this fixed in the insiders build with the default shell syntax highlighter or do we need to download another one?

Thanks

vscode-1 77-insiders

@alexr00
Copy link
Member

alexr00 commented Mar 13, 2023

@cipherdmg your issue is not yet fixed. I have opened jeff-hykin/better-shell-syntax#53 on the upstream repo for it.

@alexr00
Copy link
Member

alexr00 commented Mar 14, 2023

@cipherdmg the folks over in jeff-hykin/better-shell-syntax#53 have added a short term fix for your issue. You should see it in the next VS Code insiders build.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

7 participants