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:
parent
30d6cacb7c
commit
4675ffe963
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user