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:
parent
8818825215
commit
ee516ebf19
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue