Correctly highlight the 'any' keyword when used within other type references (#130)

Treat it the same way as the `some` keyword.
This commit is contained in:
John Sundell 2022-06-08 22:13:57 +02:00 committed by GitHub
parent e92d451f82
commit 2e3f17c2d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -342,7 +342,7 @@ private extension SwiftGrammar {
return true return true
} }
if segment.tokens.current == "some" { if segment.tokens.current.isAny(of: "some", "any") {
guard segment.tokens.previous != "case" else { guard segment.tokens.previous != "case" else {
return false return false
} }

View File

@ -1119,6 +1119,44 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
]) ])
} }
func testFunctionDeclarationWithGenericAnyParameter() {
let components = highlighter.highlight("func process(collection: any Collection<any Value>)")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("process(collection:"),
.whitespace(" "),
.token("any", .keyword),
.whitespace(" "),
.token("Collection", .type),
.plainText("<"),
.token("any", .keyword),
.whitespace(" "),
.token("Value", .type),
.plainText(">)")
])
}
func testFunctionDeclarationWithAnyDictionary() {
let components = highlighter.highlight("func process(dictionary: [String: any Value])")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("process(dictionary:"),
.whitespace(" "),
.plainText("["),
.token("String", .type),
.plainText(":"),
.whitespace(" "),
.token("any", .keyword),
.whitespace(" "),
.token("Value", .type),
.plainText("])")
])
}
func testPrefixFunctionDeclaration() { func testPrefixFunctionDeclaration() {
let components = highlighter.highlight("prefix func !(rhs: Bool) -> Bool { !rhs }") let components = highlighter.highlight("prefix func !(rhs: Bool) -> Bool { !rhs }")