Fix highlighting for inout closure arguments (#68)

This patch makes Splash correctly highlight the `inout` keyword when
it appears as part of a closure argument definition.
This commit is contained in:
John Sundell 2019-05-13 11:19:15 +02:00 committed by GitHub
parent 30d6cacb7c
commit 4675ffe963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -272,7 +272,7 @@ private extension SwiftGrammar {
}
// Don't highlight most keywords when used as a parameter label
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false") {
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout") {
guard !previousToken.isAny(of: "(", ",", ">(") else {
return false
}

View File

@ -110,6 +110,27 @@ final class ClosureTests: SyntaxHighlighterTestCase {
])
}
func testClosureWithInoutArgument() {
let components = highlighter.highlight("func add(closure: (inout Value) -> Void)")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("add(closure:"),
.whitespace(" "),
.plainText("("),
.token("inout", .keyword),
.whitespace(" "),
.token("Value", .type),
.plainText(")"),
.whitespace(" "),
.plainText("->"),
.whitespace(" "),
.token("Void", .type),
.plainText(")")
])
}
func testPassingClosureAsArgument() {
let components = highlighter.highlight("object.call({ $0 })")
@ -194,6 +215,7 @@ extension ClosureTests {
("testClosureArgumentWithSingleArgument", testClosureArgumentWithSingleArgument),
("testClosureArgumentWithMultipleArguments", testClosureArgumentWithMultipleArguments),
("testEscapingClosureArgument", testEscapingClosureArgument),
("testClosureWithInoutArgument", testClosureWithInoutArgument),
("testPassingClosureAsArgument", testPassingClosureAsArgument),
("testNestedEscapingClosure", testNestedEscapingClosure),
("testClosureArgumentShorthands", testClosureArgumentShorthands)