Skip to content

Commit

Permalink
Fix highlighting for static properties/enum cases on generic types (J…
Browse files Browse the repository at this point in the history
…ohnSundell#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.
  • Loading branch information
JohnSundell authored Oct 12, 2020
1 parent f25dd8c commit 8818825
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Splash/Grammar/SwiftGrammar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
31 changes: 31 additions & 0 deletions Tests/SplashTests/Tests/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1277,6 +1307,7 @@ extension DeclarationTests {
("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet),
("testPropertyWithSetterAccessLevel", testPropertyWithSetterAccessLevel),
("testPropertyDeclarationAfterCommentEndingWithVarKeyword", testPropertyDeclarationAfterCommentEndingWithVarKeyword),
("testPropertyDeclarationWithStaticPropertyDefaultValue", testPropertyDeclarationWithStaticPropertyDefaultValue),
("testSubscriptDeclaration", testSubscriptDeclaration),
("testGenericSubscriptDeclaration", testGenericSubscriptDeclaration),
("testDeferDeclaration", testDeferDeclaration),
Expand Down

0 comments on commit 8818825

Please sign in to comment.