Fix highlighting for keywords used as generic function parameter labels (#65)
This patch fixes highlighting for parameter labels that also match a keyword, when used within a generic function declaration.
This commit is contained in:
parent
c05038072a
commit
2b9e65e0d8
@ -271,7 +271,7 @@ private extension SwiftGrammar {
|
|||||||
|
|
||||||
// Don't highlight most keywords when used as a parameter label
|
// Don't highlight most keywords when used as a parameter label
|
||||||
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false") {
|
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false") {
|
||||||
guard !previousToken.isAny(of: "(", ",") else {
|
guard !previousToken.isAny(of: "(", ",", ">(") else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,26 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testGenericFunctionDeclarationWithKeywordArgumentLabel() {
|
||||||
|
let components = highlighter.highlight("func perform<O: AnyObject>(for object: O) {}")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("func", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("perform<O:"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("AnyObject", .type),
|
||||||
|
.plainText(">(for"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("object:"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("O", .type),
|
||||||
|
.plainText(")"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{}")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func testGenericFunctionDeclarationWithoutConstraints() {
|
func testGenericFunctionDeclarationWithoutConstraints() {
|
||||||
let components = highlighter.highlight("func hello<A, B>(a: A, b: B)")
|
let components = highlighter.highlight("func hello<A, B>(a: A, b: B)")
|
||||||
|
|
||||||
@ -857,6 +877,7 @@ extension DeclarationTests {
|
|||||||
("testPublicFunctionDeclarationWithDocumentationEndingWithDot", testPublicFunctionDeclarationWithDocumentationEndingWithDot),
|
("testPublicFunctionDeclarationWithDocumentationEndingWithDot", testPublicFunctionDeclarationWithDocumentationEndingWithDot),
|
||||||
("testFunctionDeclarationWithEmptyExternalLabel", testFunctionDeclarationWithEmptyExternalLabel),
|
("testFunctionDeclarationWithEmptyExternalLabel", testFunctionDeclarationWithEmptyExternalLabel),
|
||||||
("testFunctionDeclarationWithKeywordArgumentLabel", testFunctionDeclarationWithKeywordArgumentLabel),
|
("testFunctionDeclarationWithKeywordArgumentLabel", testFunctionDeclarationWithKeywordArgumentLabel),
|
||||||
|
("testGenericFunctionDeclarationWithKeywordArgumentLabel", testGenericFunctionDeclarationWithKeywordArgumentLabel),
|
||||||
("testGenericFunctionDeclarationWithoutConstraints", testGenericFunctionDeclarationWithoutConstraints),
|
("testGenericFunctionDeclarationWithoutConstraints", testGenericFunctionDeclarationWithoutConstraints),
|
||||||
("testGenericFunctionDeclarationWithSingleConstraint", testGenericFunctionDeclarationWithSingleConstraint),
|
("testGenericFunctionDeclarationWithSingleConstraint", testGenericFunctionDeclarationWithSingleConstraint),
|
||||||
("testGenericFunctionDeclarationWithMultipleConstraints", testGenericFunctionDeclarationWithMultipleConstraints),
|
("testGenericFunctionDeclarationWithMultipleConstraints", testGenericFunctionDeclarationWithMultipleConstraints),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user