Skip to content

Commit ee516eb

Browse files
authored
Fix highlighting for method calls named the same as a keyword (#118)
When those calls are made using trailing closure syntax.
1 parent 8818825 commit ee516eb

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

Sources/Splash/Grammar/SwiftGrammar.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,10 @@ private extension SwiftGrammar {
305305
return false
306306
}
307307

308-
guard !keywords.contains(segment.tokens.current) else {
309-
return false
308+
if segment.tokens.previous != "." {
309+
guard !keywords.contains(segment.tokens.current) else {
310+
return false
311+
}
310312
}
311313

312314
return !segment.tokens.onSameLine.contains(anyOf: controlFlowTokens)

Tests/SplashTests/Tests/FunctionCallTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
196196
])
197197
}
198198

199+
func testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax() {
200+
let components = highlighter.highlight("publisher.catch { error in }")
201+
202+
XCTAssertEqual(components, [
203+
.plainText("publisher."),
204+
.token("catch", .call),
205+
.whitespace(" "),
206+
.plainText("{"),
207+
.whitespace(" "),
208+
.plainText("error"),
209+
.whitespace(" "),
210+
.token("in", .keyword),
211+
.whitespace(" "),
212+
.plainText("}")
213+
])
214+
}
215+
199216
func testAllTestsRunOnLinux() {
200217
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
201218
}
@@ -217,7 +234,8 @@ extension FunctionCallTests {
217234
("testIndentedFunctionCalls", testIndentedFunctionCalls),
218235
("testXCTAssertCalls", testXCTAssertCalls),
219236
("testUsingTryKeywordWithinFunctionCall", testUsingTryKeywordWithinFunctionCall),
220-
("testCallingFunctionWithProjectedPropertyWrapperValue", testCallingFunctionWithProjectedPropertyWrapperValue)
237+
("testCallingFunctionWithProjectedPropertyWrapperValue", testCallingFunctionWithProjectedPropertyWrapperValue),
238+
("testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax", testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax)
221239
]
222240
}
223241
}

0 commit comments

Comments
 (0)