Skip to content

Syntax Highlight breaks with substring matching #279

Open

Description

@GrabbenD

Issue Overview

Substring matching breaks syntax highlight in ZED (which doesn't happen with VSCode nor GitHub Markdown).

Bash 5.2 enables substring matching by default (see patsub_replacement). This is particularly useful for injecting strings, but only when a $variable is present. In this example --volume=/tmp/mnt:/mnt wont be printed unless item in export MOUNTS is uncommented:

#!/usr/bin/env bash

export MOUNTS=(
  #/tmp/mnt:/mnt
)

export PARAMS=(
  "${MOUNTS[@]/*/'--volume='&}"
  --tty='1'
  --interactive='1'
)

podman run "${PARAMS[@]}" archlinux
# podman run --tty=1 --interactive=1 archlinux

Reproducible example

PARENT_FUNC() {
  local LIST=(1 2)
  export ITEMIZED=(
    #"${LIST[@]/*/'prefix'&'suffix'}" # OK
    "${LIST[@]/*/'prefix'&}"          # BREAKS HIGHLIGHT
  )

  NESTED_FUNC() {
    echo "${ITEMIZED[@]}"  # prefix1 prefix2
  }
}

PARENT_FUNC
NESTED_FUNC

Screenshots

ZED without any extensions:

  • OK
    highligh_ok

  • BROKEN
    highlight_broken

For reference, I've also tried installing d1y/bash.zed (extensions/basher) & rburmorrison/shell.zed (extensions/shell) but either behaves identically as ZED with no extensions

Environment

Zed: v0.159.7 (Zed)
OS: Arch Linux Wayland
Memory: 62.6 GiB
Architecture: x86_64
GPU: AMD Radeon RX 7900 XT (RADV NAVI31) || radv || Mesa 24.1.3-arch1.1

Activity

  1. barr-israel commented on Nov 16, 2024

    @barr-israel

    also happens with the % syntax on NeoVim, single liner that removes file extension and breaks tree-sitter:
    removed=${filename%.*}
    syntax highlighting for the entire file is gone, both in bash file and a markdown file containing a bash code block.
    I'm getting the following error log, I'm using a nearly unmodified LazyVim:

       Error  18:40:35 msg_show.emsg Error in decoration provider treesitter/highlighter.win:
    Error executing lua: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 9:4.
     Invalid node type "":
      "<"
       ^
    
    stack traceback:
    > [C]: in function '_ts_parse_query'
    > /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
    > /usr/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'
    > /usr/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get'
    > /usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:28: in function 'new'
    > /usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:243: in function 'get_query'
    > /usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:191: in function 'fn'
    > /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'
    > /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:495: in function 'for_each_tree'
    > /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:495: in function 'for_each_tree'
    > /usr/share/nvim/runtime/
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions