Merge pull request #13 from JohnSundell/keyword-parameter-labels
Don’t highlight keywords when used as a parameter label
This commit is contained in:
commit
1559117b5a
@ -213,6 +213,15 @@ private extension SwiftGrammar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let previousToken = segment.tokens.previous {
|
||||||
|
// Don't highlight most keywords when used as a parameter label
|
||||||
|
if !segment.tokens.current.isAny(of: "_", "self", "let", "var") {
|
||||||
|
guard !previousToken.isAny(of: "(", ",") else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return keywords.contains(segment.tokens.current)
|
return keywords.contains(segment.tokens.current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,21 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testFunctionDeclarationWithKeywordArgumentLabel() {
|
||||||
|
let components = highlighter.highlight("func a(for b: B)")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("func", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("a(for"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("b:"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("B", .type),
|
||||||
|
.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)")
|
||||||
|
|
||||||
@ -473,6 +488,7 @@ extension DeclarationTests {
|
|||||||
("testRequiredFunctionDeclaration", testRequiredFunctionDeclaration),
|
("testRequiredFunctionDeclaration", testRequiredFunctionDeclaration),
|
||||||
("testPublicFunctionDeclarationWithDocumentationEndingWithDot", testPublicFunctionDeclarationWithDocumentationEndingWithDot),
|
("testPublicFunctionDeclarationWithDocumentationEndingWithDot", testPublicFunctionDeclarationWithDocumentationEndingWithDot),
|
||||||
("testFunctionDeclarationWithEmptyExternalLabel", testFunctionDeclarationWithEmptyExternalLabel),
|
("testFunctionDeclarationWithEmptyExternalLabel", testFunctionDeclarationWithEmptyExternalLabel),
|
||||||
|
("testFunctionDeclarationWithKeywordArgumentLabel", testFunctionDeclarationWithKeywordArgumentLabel),
|
||||||
("testGenericFunctionDeclarationWithoutConstraints", testGenericFunctionDeclarationWithoutConstraints),
|
("testGenericFunctionDeclarationWithoutConstraints", testGenericFunctionDeclarationWithoutConstraints),
|
||||||
("testGenericFunctionDeclarationWithSingleConstraint", testGenericFunctionDeclarationWithSingleConstraint),
|
("testGenericFunctionDeclarationWithSingleConstraint", testGenericFunctionDeclarationWithSingleConstraint),
|
||||||
("testGenericFunctionDeclarationWithMultipleConstraints", testGenericFunctionDeclarationWithMultipleConstraints),
|
("testGenericFunctionDeclarationWithMultipleConstraints", testGenericFunctionDeclarationWithMultipleConstraints),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user