Correctly highlight `nil` when passed as a function argument (#87)

This patch fixes syntax highlighting when `nil` is passed to a function
that doesn’t have any parameter labels, such as `handler(nil)`.
This commit is contained in:
John Sundell 2019-11-04 11:26:15 +01:00 committed by GitHub
parent 19df647082
commit 66714d6867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -314,7 +314,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", "inout") {
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout", "nil") {
guard !previousToken.isAny(of: "(", ",", ">(") else {
return false
}

View File

@ -23,6 +23,17 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
])
}
func testFunctionCallWithNil() {
let components = highlighter.highlight("handler(nil)")
XCTAssertEqual(components, [
.token("handler", .call),
.plainText("("),
.token("nil", .keyword),
.plainText(")")
])
}
func testImplicitInitializerCall() {
let components = highlighter.highlight("let string = String()")
@ -168,6 +179,7 @@ extension FunctionCallTests {
static var allTests: [(String, TestClosure<FunctionCallTests>)] {
return [
("testFunctionCallWithIntegers", testFunctionCallWithIntegers),
("testFunctionCallWithNil", testFunctionCallWithNil),
("testImplicitInitializerCall", testImplicitInitializerCall),
("testExplicitInitializerCall", testExplicitInitializerCall),
("testDotSyntaxInitializerCall", testDotSyntaxInitializerCall),