What steps will reproduce the bug?
- 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
}
- 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.
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
What steps will reproduce the bug?
bat test.swiftWhat happens?
Only the first function declaration is fully highlighted (
funckeyword and function name get their scopes). From the second function onwards,funcand the function name lose highlighting and render as default foreground color. Attributes like@MainActorand@escapingcontinue to be highlighted on all subsequent declarations.What did you expect to happen instead?
All function declarations in a protocol should be highlighted consistently —
funcasstorage.type.function.swiftand the function name asentity.type.function.swift— regardless of position within the protocol body.Root cause
The
function-declarationcontext inSwift.sublime-syntaxonly pops on(?<=\})(closing brace of a function body). Protocol method declarations have no body, so the parser entersmeta.function-declaration.swifton the firstfuncand never exits it. All subsequent declarations are parsed inside that stuck context, where thefunction-declarationrule no longer matches.How did you install
bat?Homebrew (
brew install bat)bat version and environment
Software version
bat 0.26.1
Operating system
Command-line
Environment variables
Compile time information