Fix highlighting for method calls named the same as a keyword (#118)

When those calls are made using trailing closure syntax.
This commit is contained in:
John Sundell 2020-10-12 23:08:25 +02:00 committed by GitHub
parent 8818825215
commit ee516ebf19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -305,8 +305,10 @@ private extension SwiftGrammar {
return false
}
guard !keywords.contains(segment.tokens.current) else {
return false
if segment.tokens.previous != "." {
guard !keywords.contains(segment.tokens.current) else {
return false
}
}
return !segment.tokens.onSameLine.contains(anyOf: controlFlowTokens)

View File

@ -196,6 +196,23 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
])
}
func testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax() {
let components = highlighter.highlight("publisher.catch { error in }")
XCTAssertEqual(components, [
.plainText("publisher."),
.token("catch", .call),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("error"),
.whitespace(" "),
.token("in", .keyword),
.whitespace(" "),
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -217,7 +234,8 @@ extension FunctionCallTests {
("testIndentedFunctionCalls", testIndentedFunctionCalls),
("testXCTAssertCalls", testXCTAssertCalls),
("testUsingTryKeywordWithinFunctionCall", testUsingTryKeywordWithinFunctionCall),
("testCallingFunctionWithProjectedPropertyWrapperValue", testCallingFunctionWithProjectedPropertyWrapperValue)
("testCallingFunctionWithProjectedPropertyWrapperValue", testCallingFunctionWithProjectedPropertyWrapperValue),
("testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax", testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax)
]
}
}