Skip to content

Swift: protocol method declarations lose highlighting after the first func #3826

Description

@nermolenko-fhl

What steps will reproduce the bug?

  1. Create a Swift file with a protocol containing two or more method declarations (no function bodies):
protocol TestProtocol: AnyObject {
    @MainActor func viewController_1(
        viewModel: ViewModel1,
        onClose: @escaping () -> Void
    ) -> UIViewController

    @MainActor func viewController_2(
        viewModel: ViewModel2,
        onClose: @escaping () -> Void
    ) -> UIViewController
}
  1. Run bat test.swift

What happens?

Only the first function declaration is fully highlighted (func keyword and function name get their scopes). From the second function onwards, func and the function name lose highlighting and render as default foreground color. Attributes like @MainActor and @escaping continue to be highlighted on all subsequent declarations.

Image

What did you expect to happen instead?

All function declarations in a protocol should be highlighted consistently — func as storage.type.function.swift and the function name as entity.type.function.swift — regardless of position within the protocol body.

Root cause

The function-declaration context in Swift.sublime-syntax only pops on (?<=\}) (closing brace of a function body). Protocol method declarations have no body, so the parser enters meta.function-declaration.swift on the first func and never exits it. All subsequent declarations are parsed inside that stuck context, where the function-declaration rule no longer matches.

How did you install bat?

Homebrew (brew install bat)


bat version and environment

Software version

bat 0.26.1

Operating system

  • OS: macOS 26.5.1
  • Kernel: 25.5.0

Command-line

bat /tmp/test_proto.swift --diagnostic

Environment variables

BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
COLORTERM=truecolor
LANG=en_AU.UTF-8
SHELL=/bin/zsh
TERM=xterm-256color
XDG_CONFIG_HOME=/Users/n.ermolenko/.config

Compile time information

  • Profile: release
  • Target triple: aarch64-apple-darwin
  • OS: macos
  • Architecture: aarch64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions