Skip to content

fix(swift): keep highlighting protocol bodiless func declarations#3829

Open
momomuchu wants to merge 1 commit into
sharkdp:masterfrom
momomuchu:fix/swift-protocol-bodiless-func-highlight-3826
Open

fix(swift): keep highlighting protocol bodiless func declarations#3829
momomuchu wants to merge 1 commit into
sharkdp:masterfrom
momomuchu:fix/swift-protocol-bodiless-func-highlight-3826

Conversation

@momomuchu

Copy link
Copy Markdown

In a Swift protocol, only the first bodiless func was highlighted; later declarations rendered as plain text.

The function-declaration and function-result contexts in Swift.sublime-syntax only popped on a function body's closing brace (?<=\}). Protocol methods have no body, so the parser entered the context on the first func and never left, and every later declaration lost its scopes.

The fix adds an end-of-line pop to both contexts, so a bodiless declaration exits at end of line. Braced functions are unaffected since their { is matched before the line end.

Extends tests/syntax-tests/source/Swift/test.swift with a protocol of multiple bodiless funcs and regenerates the highlighted fixture; the regression harness reports no changes for the fixed binary, and the fixture differs without the fix. syntaxes.bin is intentionally not included, per doc/assets.md.

Closes #3826

Protocol method requirements have no function body, so the
`function-declaration` (and `function-result`) contexts in
Swift.sublime-syntax only popped on `(?<=\})`, the closing brace of a
body. A bodiless declaration never produces that brace, so the parser
entered `meta.function-declaration.swift` on the first `func` and never
left it. Every subsequent declaration in the protocol was then parsed
inside that stuck context (where the `function-declaration` rule no
longer matches), losing the `storage.type.function` / `entity.type.function`
scopes on `func` and the method name.

Add an end-of-line pop to both contexts so a bodiless declaration exits
cleanly at the end of its line. Normal (braced) functions are unaffected:
their `{` is matched before EOL, so the code-block push still wins.

Extends the Swift syntax regression fixture with a protocol containing
multiple bodiless funcs. Closes sharkdp#3826.
@momomuchu momomuchu force-pushed the fix/swift-protocol-bodiless-func-highlight-3826 branch from 4ff3cc7 to 8574e4f Compare July 4, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift: protocol method declarations lose highlighting after the first func

1 participant