Correctly highlight subclasses inheriting from a generic superclass (#108)

This change fixes syntax highlighting in situations when a subclass is
inheriting from a superclass that’s generic.
This commit is contained in:
John Sundell 2020-05-25 01:18:22 +02:00 committed by GitHub
parent 3e400c0874
commit ca9a1b7bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -419,7 +419,7 @@ private extension SwiftGrammar {
}
// Handling generic lists for parameters, rather than declarations
if foundOpeningBracket && token == ":" {
if foundOpeningBracket && token.isAny(of: ":", ">:") {
return true
}

View File

@ -368,6 +368,23 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testGenericSubclassDeclaration() {
let components = highlighter.highlight("class Promise<Value>: Future<Value> {}")
XCTAssertEqual(components, [
.token("class", .keyword),
.whitespace(" "),
.plainText("Promise<Value>:"),
.whitespace(" "),
.token("Future", .type),
.plainText("<"),
.token("Value", .type),
.plainText(">"),
.whitespace(" "),
.plainText("{}")
])
}
func testProtocolDeclaration() {
let components = highlighter.highlight("""
protocol Hello {
@ -1161,6 +1178,7 @@ extension DeclarationTests {
("testClassDeclarationWithDeinit", testClassDeclarationWithDeinit),
("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances),
("testSubclassDeclaration", testSubclassDeclaration),
("testGenericSubclassDeclaration", testGenericSubclassDeclaration),
("testProtocolDeclaration", testProtocolDeclaration),
("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes),
("testExtensionDeclaration", testExtensionDeclaration),