Fix highlighting for comments ending with punctuation (#81)

This patch fixes highlighting of any type declarations that follow
a comment which was ended with a punctuation character. The fix is
to only look at previous tokens on the same line when determining
whether a given token is a keyword.
This commit is contained in:
John Sundell 2019-08-07 15:51:16 +02:00 committed by GitHub
parent 016aaa13f3
commit e03dac1dd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -283,7 +283,8 @@ private extension SwiftGrammar {
}
}
if let previousToken = segment.tokens.previous {
if !segment.tokens.onSameLine.isEmpty,
let previousToken = segment.tokens.previous {
// Highlight the '(set)' part of setter access modifiers
switch segment.tokens.current {
case "(":

View File

@ -112,6 +112,25 @@ final class CommentTests: SyntaxHighlighterTestCase {
])
}
func testCommentEndingWithComma() {
let components = highlighter.highlight("""
// Hello,
class World {}
""")
XCTAssertEqual(components, [
.token("//", .comment),
.whitespace(" "),
.token("Hello,", .comment),
.whitespace("\n"),
.token("class", .keyword),
.whitespace(" "),
.plainText("World"),
.whitespace(" "),
.plainText("{}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -123,7 +142,8 @@ extension CommentTests {
("testSingleLineComment", testSingleLineComment),
("testMultiLineComment", testMultiLineComment),
("testMultiLineCommentWithDoubleAsterisks", testMultiLineCommentWithDoubleAsterisks),
("testMutliLineDocumentationComment", testMutliLineDocumentationComment)
("testMutliLineDocumentationComment", testMutliLineDocumentationComment),
("testCommentEndingWithComma", testCommentEndingWithComma)
]
}
}