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:
parent
19df647082
commit
66714d6867
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue