Skip to content

Commit

Permalink
Don’t highlight generic parameter types used in initializer declarati…
Browse files Browse the repository at this point in the history
…ons (#107)

This change makes Splash stop highlighting generic types that are attached
to an initializer declaration, and instead now only highlights their
constraints, just like within other kinds of generic type lists.
  • Loading branch information
JohnSundell committed May 24, 2020
1 parent 9798c4f commit 3e400c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Splash/Grammar/SwiftGrammar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private extension SwiftGrammar {
static let declarationKeywords: Set<String> = [
"class", "struct", "enum", "func",
"protocol", "typealias", "import",
"associatedtype", "subscript"
"associatedtype", "subscript", "init"
]

struct PreprocessingRule: SyntaxRule {
Expand Down
32 changes: 31 additions & 1 deletion Tests/SplashTests/Tests/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,35 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}

func testGenericInitializerDeclaration() {
let components = highlighter.highlight("""
struct Box {
init<T: Model>(model: T) {}
}
""")

XCTAssertEqual(components, [
.token("struct", .keyword),
.whitespace(" "),
.plainText("Box"),
.whitespace(" "),
.plainText("{"),
.whitespace("\n "),
.token("init", .keyword),
.plainText("<T:"),
.whitespace(" "),
.token("Model", .type),
.plainText(">(model:"),
.whitespace(" "),
.token("T", .type),
.plainText(")"),
.whitespace(" "),
.plainText("{}"),
.whitespace("\n"),
.plainText("}")
])
}

func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
Expand Down Expand Up @@ -1157,7 +1186,8 @@ extension DeclarationTests {
("testPrefixFunctionDeclaration", testPrefixFunctionDeclaration),
("testEnumDeclarationWithSomeCase", testEnumDeclarationWithSomeCase),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration),
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations)
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations),
("testGenericInitializerDeclaration", testGenericInitializerDeclaration)
]
}
}

0 comments on commit 3e400c0

Please sign in to comment.