fix(swift): keep highlighting protocol bodiless func declarations#3829
Open
momomuchu wants to merge 1 commit into
Open
fix(swift): keep highlighting protocol bodiless func declarations#3829momomuchu wants to merge 1 commit into
momomuchu wants to merge 1 commit into
Conversation
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.
4ff3cc7 to
8574e4f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a Swift
protocol, only the first bodilessfuncwas highlighted; later declarations rendered as plain text.The
function-declarationandfunction-resultcontexts inSwift.sublime-syntaxonly popped on a function body's closing brace(?<=\}). Protocol methods have no body, so the parser entered the context on the firstfuncand 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.swiftwith 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.binis intentionally not included, per doc/assets.md.Closes #3826