Fix highlighting for static properties/enum cases on generic types (#117)

This patch makes Splash correctly render enum cases and static properties
that are defined on a generic type when those symbols are references along
with their enclosing type.
This commit is contained in:
John Sundell 2020-10-12 22:27:00 +02:00 committed by GitHub
parent f25dd8c9f1
commit 8818825215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -503,7 +503,7 @@ private extension SwiftGrammar {
return false
}
guard segment.tokens.previous.isAny(of: ".", "?.", "().", ").") else {
guard segment.tokens.previous.isAny(of: ".", "?.", "().", ").", ">.") else {
return false
}

View File

@ -729,6 +729,36 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testPropertyDeclarationWithStaticPropertyDefaultValue() {
let components = highlighter.highlight("""
class ViewModel {
var state = LoadingState<Output>.idle
}
""")
XCTAssertEqual(components, [
.token("class", .keyword),
.whitespace(" "),
.plainText("ViewModel"),
.whitespace(" "),
.plainText("{"),
.whitespace("\n "),
.token("var", .keyword),
.whitespace(" "),
.plainText("state"),
.whitespace(" "),
.plainText("="),
.whitespace(" "),
.token("LoadingState", .type),
.plainText("<"),
.token("Output", .type),
.plainText(">."),
.token("idle", .property),
.whitespace("\n"),
.plainText("}")
])
}
func testSubscriptDeclaration() {
let components = highlighter.highlight("""
extension Collection {
@ -1277,6 +1307,7 @@ extension DeclarationTests {
("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet),
("testPropertyWithSetterAccessLevel", testPropertyWithSetterAccessLevel),
("testPropertyDeclarationAfterCommentEndingWithVarKeyword", testPropertyDeclarationAfterCommentEndingWithVarKeyword),
("testPropertyDeclarationWithStaticPropertyDefaultValue", testPropertyDeclarationWithStaticPropertyDefaultValue),
("testSubscriptDeclaration", testSubscriptDeclaration),
("testGenericSubscriptDeclaration", testGenericSubscriptDeclaration),
("testDeferDeclaration", testDeferDeclaration),