Fix syntax highlighting for leading function calls within closures (#102)

This patch fixes syntax highlighting when a function call appears as the
first expression within a closure that accepts arguments or capture lists
using the ‘in’ keyword.
This commit is contained in:
John Sundell 2020-04-16 19:29:01 +02:00 committed by GitHub
parent 26d4bbe7ca
commit 8e96992997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -231,6 +231,7 @@ private extension SwiftGrammar {
keywordsToAvoid.remove("try")
keywordsToAvoid.remove("throw")
keywordsToAvoid.remove("if")
keywordsToAvoid.remove("in")
self.keywordsToAvoid = keywordsToAvoid
var callLikeKeywords = accessControlKeywords

View File

@ -241,6 +241,25 @@ final class ClosureTests: SyntaxHighlighterTestCase {
])
}
func testClosureWithSingleFunctionCall() {
let components = highlighter.highlight("closure { a in call(a) }")
XCTAssertEqual(components, [
.token("closure", .call),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("a"),
.whitespace(" "),
.token("in", .keyword),
.whitespace(" "),
.token("call", .call),
.plainText("(a)"),
.whitespace(" "),
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -260,7 +279,8 @@ extension ClosureTests {
("testNestedEscapingClosure", testNestedEscapingClosure),
("testClosureArgumentShorthands", testClosureArgumentShorthands),
("testClosureWithWeakSelfCaptureList", testClosureWithWeakSelfCaptureList),
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList)
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList),
("testClosureWithSingleFunctionCall", testClosureWithSingleFunctionCall)
]
}
}