Skip to content

Bash function names starting with keywords are incorrectly highlighted #1481

Open

Description

@callahanp

Code editor

Visual Studio Code

Platform

Ubuntu 26.04

Version

VSCode extension version 1.43.2

What steps will reproduce the behavior?

#!/bin/bash

# I named a bunch of functions starting with the string for- 
# and found an "issue" with syntax highlighting.

# note that functions starting with different keywords may be highlighted differently
# and that the initial highlighting of the function name does not match an ivocation
# of the function for some keywords.

# for and if are provided as examples.  There are bound to be more.

# Here's a bit of silly code demonstrating the "issue". The behavior shows up in VSCode, but this section of the issue report is Markdown and doesn't show it.  See below for a screenshot.

normal-function() {
    return 0
}
if normal-function; then
    echo "we're all in this together"
fi

for_one() { #using underscore instead of a hyphen does not show the issue.
    return 1
}
for-one() {  # for is purple, one is white
    return 1
}
for-all() {
    return 0
}
if-for-all() { #if-for-all is light purple same as normal
    return 0
}
if for-all; then
    echo "for-all returned successfully"
fi
if-one() {
    return 42
}
if ! if-one; then
    echo "if-one returned questionably"
fi

if for-one; then
    echo "for-one returned un-successfully"
fi

if if-for-all; then  # if- and -all are white, for is purple.
    echo "if-for-all returned conditionally and hopefully successfully"
fi

How often does it reproduce? Is there a required condition?

Easily reproduced.: Create a fuinction name with words separated by hyphens and starting with a bash keyword. Then call it.

What is the expected behavior?

Function names always highlight correctly purple in definition, orange when referenced.

What do you see instead?

Image

Additional information

Easy enough to work around.

Activity

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